Azure Event Hubs WebSockets and Proxy support

There are a lot of challenges when we are talking of real-time applications especially on the protocols we need to pick as to who can become better candidates. Now what is meant by better candidates? Take HTTP for instance, where real-time applications work through the challenge-response principle. Each time a request has to be placed in to get data and keeping up with the real-time’ness would be a challenge. You also need to poll in such situations.

These shortcomings can be addressed with WebSockets which lets server and clients to exchange messages once the connection is established. Also, the server need not be polled to get the data when available, making it more suitable to the real-time situations. This also optimizes the bandwidth and provides updates to the clients when available.

Why WebSockets using AMQP?

While WebSockets fit the real-time updates and maintain the established connection to exchange messages between client and server, you also need an efficient messaging protocol like AMQP. Couple of advantages can be listed here like the different modes of operation it offers, the binary packing format (that lets you pack different types of data). The stand alone broker (server end of AMQP) is capable of handling the state thus providing a central broker for all the clients (no need for many peer-to-peer links). You can refer this article to learn more about AMQP 1.0 used by Event Hubs.

Thus, a self-sufficient message broker (AMQP broker) and transport layer (WebSockets) make it an efficient real-time communication through servers and browser clients.

Event Hubs supports the WebSockets with AMQP with this release – (Event Hubs Clients 1.1.0 for Java). The maven packages for the release can be found here. Alternatively, you can download from here. Our GitHub release for new clients can be found here.

Proxy support over WebSockets

WebSockets with AMQP satisfies the duplex communication with a remote host for real-time on a single socket. But big enterprises also call for enterprise content filtering. This poses the common challenges of security, firewalls through private networks, enterprise boundaries where the proxy severs monitor and close the connection if open for a significant time.

Event Hubs team, now provides the Proxy support with basic authentication through this release – (Event Hubs Clients 1.2.0 for Java). The maven packages for the release can be found here. Alternatively, you can download from here. Our GitHub release for new clients can be found here.

Our attempt with these release is to address the WebSockets and Proxy support. Let us know if these satisfy your scenarios or we need to add more supporting cases.

Below are the release summaries (which can also be found on GitHub - https://github.com/Azure/azure-event-hubs-java/releases/)

1.1.0

com.microsoft.azure.eventhubs

New Features

  • WebSockets Support (#362)
    Amqp over WebSockets is particularly useful when enterprise policies (ex: firewall outbound port rules) restrict traffic on the default Amqp secure port (5671). To send or receive to Microsoft Azure Event Hubs over websockets - which uses port 443, set the TransportType on ConnectionStringBuilder, like this:

connectionStringBuilder.setTransportType(TransportType.AmqpWebSockets)

Bug fixes

  • Correct the ExceptionContract when request-response channel closes with transient error (#372)
  • PartitionReceiver and PartitionSender creation should participate in RetryPolicy (#373)

1.2.0

This major release targets the following additions,

com.microsoft.azure.eventhubs

New Features

  • Proxy Support - with Basic Authentication (#362)
    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 
ProxySelector.setDefault(new ProxySelector() {            
                   @Override            
                   public List<Proxy> select(URI uri) {                
                      LinkedList<Proxy> proxies = new LinkedList<>();                
                      proxies.add(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIpAddressStr, proxyPort)));                
                      return proxies;     
                  } 
                  @Override
                  public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
                      // trace and follow up on why proxy server is down
                  } 
              }); 
// step-2: 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

Next Steps

The AMQP WebSockets support is built on the specifications found here

Try this new library and let us know what you think!

Happy event-ing!

Event Hubs team