Skip to content

IllegalStateException: Cannot Subscrie.Processor is already terminated

I created a new eventhub and trying to publish messages to eventHubA. When I am trying to send messages to eventhub , I get the following error:

java.lang.IllegalStateException: namespace[xxxxx] entityPath[xxxxx]: Cannot subscribe. Processor is already terminated at

Below is the code snippet i am using:

public void send(Response response) {
        String responseInString = JsonHandlingUtil.objectToJsonString(response);

        EventData eventData = new EventData(responseInString);
        // create a batch
        EventDataBatch eventDataBatch = producer.createBatch();

        // try to add the event from the array to the batch
        if (!eventDataBatch.tryAdd(eventData)) {
            // if the batch is full, send it and then create a new batch
            eventDataBatch = producer.createBatch();

            // Try to add that event that couldn't fit before.
            if (!eventDataBatch.tryAdd(eventData)) {
                throw new IllegalArgumentException("Event is too large for an empty batch. Max size: "
                        + eventDataBatch.getMaxSizeInBytes());
        // send the last batch of remaining events
        if (eventDataBatch.getCount() > 0) {

I have defined the eventhubProducerClient as a Bean.

    public EventHubProducerClient eventHubProducerClient() {
        return new EventHubClientBuilder()
                .connectionString(connectionString, eventHubName)

Below is my gradle dependencies

>    //eventhub
>         implementation ''
>         implementation group: 'io.projectreactor', name: 'reactor-core', version: '3.4.6'


From the follow-up question, it would appear that the root cause has been confirmed as the producer.close() call in the send method.

Since it appears that he producer is being managed as a singleton by the application, the mitigation would be to call close at the point when events are no longer going to be published, such as when the application is shutting down.