简体   繁体   中英

How to send message to the rabbitmq queue using spring integration java DSL

I wrote simple sample to read text from console and send it to the rabbitMq server:

@Configuration
@EnableIntegration
@IntegrationComponentScan
public class Config {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Bean
    public IntegrationFlow fromConsoleToRabbitFlow() {
        return IntegrationFlows.from(consoleSource(), c -> c.id("consoleInput")
                .poller(Pollers.fixedRate(1000))
                .autoStartup(true)
        ).channel("consoleOutputChannel")
                .handle(Amqp.outboundAdapter(amqpTemplate).routingKey("my_spring_integration_queue"))
                .get();
    }

    public MessageSource<String> consoleSource() {
        return CharacterStreamReadingMessageSource.stdin();
    }

}

It looks like almost working solution but I can't find my_spring_integration_queue in rabbitmq admin console:

在此处输入图片说明

But I can't find anything related to 'my_spring_integration_queue' on other tab. Where can I find it ?

I expect that application will create queue if it doesn't exist. I was not able to find a method for send into the queur so I used .routingKey method. I also tried .exchangeName method but it lead to the:

32019-08-27 13:26:15.972 ERROR 16372 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'my_spring_integration_queue' in vhost '/', class-id=60, method-id=40)

PS

the Queue tab looks like this:

在此处输入图片说明

You either need to add the queue manually or use a RabbitAdmin @Bean to automatically declare it for you - the admin will find all beans of type Queue and declare them.

If you are using Spring Boot, it will automatically configure an admin bean for you so you just need the Queue @Bean .

See Configuring the Broker .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM