random 'Dispatcher has no subscribers for channel' behaviour
See original GitHub issueHi – I’ve got a spring boot application where a front end listens for RESTful requests and sends messages to another spring boot application in the same JVM to do work. the front end, before sending, creates a new topic on the fly based on a sequence number and includes that sequence number in the request to the back so that it knows to which topic to send the reply. it blocks for 20 seconds in polling for the response. it then deletes the topic when it’s done receiving the response (or after timeout). the backend is an @StreamListener
my problem is that the application behaves randomly between bootruns -
- round trip requests/responses work 100%
- round trip requests/responses work after a first failure where the backend replies on the unique response topic, but the front end, on a poll of 20 seconds, times out with no response
- 100% failure where the logs say ‘Dispatcher has no subscribers for channel’ and the backend listener method is never called
- same as 2 or 3, but after starting up, the listener picks up all of the “lost” messages from the previous round of tests
I’m somewhat new to Spring, but I’ve scoured the net for samples and pieced this together. why would it work randomly like that?
The consumer… note that logging shows that the @PostConstruct method is always invoked without fail. I tried the class as a Service as well.
@Component
@Slf4j
public class MessageConsumer {
@Autowired
KafkaTemplate<String, String> kafkaTemplate;
@Autowired
JsonMapper jsonMapper;
@PostConstruct
public void init() {
System.out.println("MessageConsumer.init()");
log.debug("MessageConsumer.init()");
}
@StreamListener(PartnerIntegrationRequest.PARTNER_INTEGRATION_REQUEST_LISTENER)
public void receive(String payload) {
log.info("got message: " + payload);
Map<String, Object> payloadData = jsonMapper.parse(payload);
String transactionId = (String) payloadData.get(Constants.TRANSACTION_ID.getValue());
payloadData.put(Constants.STATUS.getValue(), "success");
String topicName = "response-" + transactionId;
log.debug("replying to topic ["+topicName+"]");
kafkaTemplate.send(topicName, transactionId, jsonMapper.stringify(payloadData));
}
}
The interface …
public interface PartnerIntegrationRequest {
public static final String PARTNER_INTEGRATION_REQUEST_PRODUCER = "partnerIntegrationRequestProducer";
public static final String PARTNER_INTEGRATION_REQUEST_LISTENER = "partnerIntegrationRequestListener";
@Output
MessageChannel partnerIntegrationRequestProducer();
@Input
SubscribableChannel partnerIntegrationRequestListener();
}
Front end sending code…
private boolean sendMessageToPartnerIntegration(String stringify) {
log.debug("sending message: {}", stringify);
boolean result = partnerIntegrationRequest.partnerIntegrationRequestProducer().send(new GenericMessage<String>(stringify),
10000);
log.debug("send result {}", ""+result);
return result;
}
and front-end properties:
spring.cloud.stream.bindings.partnerIntegrationRequestProducer.destination=partnerIntegrationRequestListener
spring.cloud.stream.bindings.partnerIntegrationRequestProducer.content-type=application/json
spring.cloud.stream.bindings.partnerIntegrationRequestListener.destination=partnerIntegrationRequestListener
spring.cloud.stream.bindings.partnerIntegrationRequestListener.content-type=application/json
spring.cloud.stream.bindings.partnerIntegrationRequestListener.group=integrationsGroup
spring.cloud.stream.bindings.partnerIntegrationResponse.destination=endpointsResponseTopic
spring.cloud.stream.bindings.partnerIntegrationResponse.content-type=application/json
#spring.cloud.stream.bindings.partnerIntegrationResponse.group=endpointsGroup
spring.cloud.stream.kafka.bindings.input.consumer.resetOffsets=true
for the backend properties, they are identical except that I have resetOffsets commented out. Hacking away with various little tweaks to see it work or not.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)

Top Related StackOverflow Question
@pts-danielmanley Thanks for reaching out.
Dispatcher has no subscribers for channeltypically means that some beans are initialized in the wrong order. It’s hard to tell what is going on there just from publishing/subscribing code. Would it be possible to publish a complete example that reproduces what you’re experiencing?@pts-danielmanley we just ran into this issue in our application that is using consumers and producers in the same application over the same channels. It seems like there is an opportunity for improvement here: the framework could throw an error if it attempts to bind a consumer and producer on the same channel name?