Reputation: 1
I am trying to use Spring Cloud Stream Kafka Binding to send and receive messages with a local zookeeper and kafka server. However, when starting up Spring MVC server, I am seeing the following exception:
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:154) ~[spring-integration-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121) ~[spring-integration-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
... 28 common frames omitted
The server is very simple, one class and one spring application property file:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
import java.util.Map;
@RestController
@EnableBinding(ProducerChannels.class)
@SpringBootApplication
public class ProducerApplication {
private final MessageChannel consumer;
public ProducerApplication(ProducerChannels channels){
this.consumer = channels.consumer();
}
@PostMapping("/greet/{name}")
public void publish(@RequestBody Map<String, String> name){
String greeting = "Hello, " + name + "!";
Message<String> msg = MessageBuilder.withPayload(greeting).build();
consumer.send(msg);
}
public static void main(String[] args) {
SpringApplication.run(ProducerApplication.class, args);
}
}
interface ProducerChannels {
@Output
MessageChannel consumer();
}
Blockquote spring.cloud.stream.kafka.bindings.consumer.destination = consumer server.port=8080
What else do I need to do to configure Spring Cloud Stream?
Upvotes: 0
Views: 939
Reputation: 595
consumer is a special keyword. You shouldn't use it. I think it will happen if you fix it as below.
public interface ProducerChannels {
String OUTPUT = "example-topic";
@Output(OUTPUT)
MessageChannel exampleTopic();
}
application.yml file
spring:
cloud:
stream:
kafka:
binder:
brokers: localhost:9092
bindings:
example-topic:
destination: example-topic
contentType: application/json
Or
spring.cloud.stream.bindings.exampleTopic.destination= example-topic
Upvotes: 0
Reputation: 174504
What version(s) are you using? I just pasted your code into a boot 1.4.2 app (1.1.0.RELEASE for the stream starter) and it works fine for me.
Upvotes: 1