Skip to content

1.2.0

Compare
Choose a tag to compare
@SreeramGarlapati SreeramGarlapati released this 10 Nov 18:53
· 8 commits to master since this release

com.microsoft.azure.eventhubs

New Features

Proxy Support - with Basic Authentication (#378)

Amqp over WebSockets with proxy support is particularly useful when enterprises want to stream data from on-premise to cloud and IT policies restrict all outbound traffic to flow only via a Proxy Server. To send to or receive from Microsoft Azure Event Hubs via proxy server, set the HTTP proxy settings & set the TransportType on ConnectionStringBuilder to AMQP_WEB_SOCKETS, and you are all set!

Step-1: Set the proxy server settings

Here's more help on setting jdk proxy properties.

// Way 1: set the system-wide http proxy settings; azure-eventhubs library will automatically use them if you use TransportType=AMQP_WEB_SOCKETS
java -Dhttp.proxyHost=ipAddress -Dhttp.proxyPort=8080` ...

or

// Way 2: set the ProxySelector API; which offers the flexibility to select Proxy Server based on the Target URI.
ProxySelector systemDefaultSelector = ProxySelector.getDefault();
ProxySelector.setDefault(new ProxySelector() {
            @Override
            public List<Proxy> select(URI uri) {
                if (uri != null
                        && uri.getHost() != null
                        && uri.getHost().equalsIgnoreCase("eventhubsnamespace.servicebus.windows.net")) {
                    LinkedList<Proxy> proxies = new LinkedList<>();
                    proxies.add(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIpAddressStr, proxyPort)));
                    return proxies;
                }

                // preserve system default selector for the rest
                return systemDefaultSelector.select(uri);
            }
            @Override
            public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
                // trace and follow up on why proxy server is down
            }
        });
Step-2: Set the Proxy Authentication details

Note: The jdk setting for disabling authentication schemes (-Djdk.http.auth.tunneling.disabledSchemes) has NO effect on BasicAuthentication support for this package version. i.e., no matter what the value of the flag -Djdk.http.auth.tunneling.disabledSchemes is - BasicAuthentication is used. azure-eventhubs package depends on the package, qpid-proton-j-extensions for authenticating with Proxy, and this package doesn't hook into the 'disabledSchemes jdk` setting.

// if the proxy being used, doesn't need any Authentication - "setting Authenticator" step may be omitted
Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                if (this.getRequestorType() == RequestorType.PROXY
                        && this.getRequestingScheme().equalsIgnoreCase("http")
                        && this.getRequestingHost().equals(proxyIpAddressStr)
                        && this.getRequestingPort() == proxyHostPort) {
                    return new PasswordAuthentication("userName", "password".toCharArray());
                }

                return super.getPasswordAuthentication();
            }
        });
Step-3: Configure EventHubClient transport to AmqpWebSockets
connectionStringBuilder.setTransportType(TransportType.AMQP_WEB_SOCKETS);
EventHubClient ehClient = EventHubClient.createSync(connectionStringBuilder.toString()....);

// hereon, this ehClient instance is ready to talk to EventHub service via the proxy server

Bug fixes

Fix EventHub PartitionReceiver.receive() API behavior on transient errors (#381)

Here's the corresponding Maven package:
https://mvnrepository.com/artifact/com.microsoft.azure/azure-eventhubs/1.2.0
http://repo1.maven.org/maven2/com/microsoft/azure/azure-eventhubs/1.2.0/