0

I'm trying to set up a very basic proof of concept to link a Spring application to an Azure Event Hub. I keep getting this log in my startup:

[2021-11-17 16:49:18.343 ERROR 25816 --- [           main] o.s.cloud.stream.binding.BindingService : Failed to create consumer binding; retrying in 30 seconds    
...
Caused by: java.lang.IllegalArgumentException: Cannot use a proxy when TransportType is not AMQP Web Sockets.
    at com.azure.messaging.eventhubs.EventHubClientBuilder.getConnectionOptions(EventHubClientBuilder.java:764) ~[azure-messaging-eventhubs-5.10.2.jar:5.10.2]
    at com.azure.messaging.eventhubs.EventHubClientBuilder.buildConnectionProcessor(EventHubClientBuilder.java:705) ~[azure-messaging-eventhubs-5.10.2.jar:5.10.2]
    at com.azure.messaging.eventhubs.EventHubClientBuilder.buildAsyncClient(EventHubClientBuilder.java:638) ~[azure-messaging-eventhubs-5.10.2.jar:5.10.2]
    at com.azure.messaging.eventhubs.EventProcessorClient.<init>(EventProcessorClient.java:89) ~[azure-messaging-eventhubs-5.10.2.jar:5.10.2]
    at com.azure.messaging.eventhubs.EventProcessorClientBuilder.buildEventProcessorClient(EventProcessorClientBuilder.java:585) ~[azure-messaging-eventhubs-5.10.2.jar:5.10.2]
...

This is despite the fact that I defined beans for EventHubProducerAsyncClient, EventHubConsumerAsyncClient, and EventProcessorClient that explicitly set the transport type to AMQP_WEB_SOCKETS. See here:

Producer:

@Bean
    public EventHubProducerAsyncClient eventHubProducerAsyncClient() {
         return new EventHubClientBuilder()
                 .connectionString(connectionString)
                 .proxyOptions(new ProxyOptions(
                            ProxyAuthenticationType.NONE,
                            new Proxy(Proxy.Type.HTTP, new InetSocketAddress("my proxy address", 8080)),
                            null, null
                        ))
                 .transportType(AmqpTransportType.AMQP_WEB_SOCKETS)
                 .buildAsyncProducerClient();
    }

Consumer:

@Bean
    public EventHubConsumerAsyncClient eventHubConsumerAsyncClient() {
        return new EventHubClientBuilder()
                .connectionString(connectionString)
                .proxyOptions(new ProxyOptions(
                        ProxyAuthenticationType.NONE,
                        new Proxy(Proxy.Type.HTTP, new InetSocketAddress("my proxy address", 8080)),
                        null, null
                    ))
                .transportType(AmqpTransportType.AMQP_WEB_SOCKETS)
                .consumerGroup(DEFAULT_CONSUMER_GROUP_NAME)
                .buildAsyncConsumerClient();
    }

EventProcessor:

    private static void onEvent(EventContext eventContext) {
        PartitionContext partition = eventContext.getPartitionContext();
        LOGGER.info("Received events from partition: " + partition.getPartitionId());
    
        EventData event = eventContext.getEventData();
        LOGGER.info("Sequence number: " + event.getSequenceNumber());
        LOGGER.info("Contents: " + new String(event.getBody(), StandardCharsets.UTF_8));
    }
    
    @Bean
    public EventProcessorClient eventProcessorClient() {
        
        BlobContainerAsyncClient blobClient = new BlobContainerClientBuilder()
                .connectionString(storageConnectionString)
                .containerName(storageContainerName)
                .buildAsyncClient();
                
        return new EventProcessorClientBuilder()
                .connectionString(connectionString)
                
                .consumerGroup(DEFAULT_CONSUMER_GROUP_NAME)
                .checkpointStore(new BlobCheckpointStore(blobClient))
                .processEvent(eventContext -> onEvent(eventContext))
                .processError(context -> {
                    LOGGER.error("Error occurred on partition: %s. Error: %s%n",
                            context.getPartitionContext().getPartitionId(), context.getThrowable());
                })
                
                .processPartitionInitialization(initializationContext -> {
                    LOGGER.info("Started receiving on partition: %s%n",
                            initializationContext.getPartitionContext().getPartitionId());
                })
                .processPartitionClose(closeContext -> {
                    LOGGER.info("Stopped receiving on partition: %s. Reason: %s%n",
                            closeContext.getPartitionContext().getPartitionId(),
                            closeContext.getCloseReason());
                })
                .proxyOptions(new ProxyOptions(
                        ProxyAuthenticationType.NONE,
                        new Proxy(Proxy.Type.HTTP, new InetSocketAddress("my proxy address", 8080)),
                        null, null
                    ))
                .transportType(AmqpTransportType.AMQP_WEB_SOCKETS)
                .buildEventProcessorClient();
    }

Am I missing something obvious here? I don't understand how it can complain about TransportType not being AMQP Web Sockets when its explicitly defined.

MogDog
  • 35
  • 7
  • I ran your code for EventProcessor as-is and I was able to build the processor and run it. We haven't updated that code path in awhile. I checked over the code and what EventProcessorClientBuilder does is pass the arguments to the underlying EventHubClientBuilder as-is. If possible could you create a minimal repro project for this? – Connie Yau Nov 18 '21 at 17:53
  • Hi thanks for the reply. I think there's something strange going on with the proxies in general. If I set `java.net.useSystemProxies` to "false", I get: `java.lang.NullPointerException: Cannot invoke "com.azure.core.http.ProxyOptions.getType()" because "coreProxyOptions" is null` If I set it to "true" I get the IllegalArgumentException in the original post. If I comment it out (don't set it at all), I get connection timeouts to the eventHub: `AmqpException: Connection timed out: no further information`. Is there something wrong with my proxy setup? – MogDog Nov 18 '21 at 22:27

0 Answers0