У Dispatcher нет подписчиков на канал 'unknown.channel.name - PullRequest
0 голосов
/ 26 мая 2019

Я пытаюсь запустить издателя и подписчика, используя пружинную привязку.

удостоверился, что пункт назначения (обмен) создан локально на rabbit-mq.

издатель (app.yml)

spring:
  cloud:
    stream:
      bindings:
        output:
          destination: HelloDestination
  rabbitmq:
    addresses: xxx.xxx.xx.xxx

Абонент (app.yml)

spring:
  cloud:
    stream:
      bindings:
        input:
          destination: HelloDestination
  rabbitmq:
    addresses: xxx.xxx.xx.xxx
server:
  port: 8081

издатель (pom.yml)

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>

Подписчик (pom.yml)

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>

Издатель (исходный файл Java)

@SpringBootApplication
@EnableBinding(Source.class)
public class Demo1Application {

    //@Autowired
    //private static MessageChannel output;

    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);

        String sampleMessage = "Hello";
        Message<String> message =
                MessageBuilder.withPayload("Hello World").build();

        MessageChannel output = new DirectChannel();

        output.send(message);   

    }

}

// потребитель (исходный файл)

@SpringBootApplication
@EnableBinding(Sink.class)
public class Demo2Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo2Application.class, args);
    }

    @StreamListener(Sink.INPUT)
    public void listenerMethod(Message<String> message)
    {
        System.out.println("The Message is :"+message);
    }
}

// ----

После всего, я вижу созданный обмен и также сообщение об обмене. Потребитель запускается просто отлично. но производитель задыхается при попытке отправить сообщение с сообщением об ошибке

Exception in thread "main" org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'unknown.channel.name'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=Hello World, headers={id=ccf86001-5dba-6c64-bc76-e1f58782de42, timestamp=1558883876384}], failedMessage=GenericMessage [payload=Hello World, headers={id=ccf86001-5dba-6c64-bc76-e1f58782de42, timestamp=1558883876384}]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:461)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
    at com.example.demo.Demo1Application.main(Demo1Application.java:29)
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=Hello World, headers={id=ccf86001-5dba-6c64-bc76-e1f58782de42, timestamp=1558883876384}]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscri

Я ожидал, что сообщение будет прочитано.

1 Ответ

0 голосов
/ 26 мая 2019

Вам нужно получить 'выход' канала из контекста приложения, возвращенного методом run (), вместо создания собственного DirectChannel.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...