久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何通過 MQTT 傳輸并使用 RabbitMQ 和 Spring-AMQP 在

How can I transmit via MQTT and Receive on AMQP with RabbitMQ and Spring-AMQP(如何通過 MQTT 傳輸并使用 RabbitMQ 和 Spring-AMQP 在 AMQP 上接收)
本文介紹了如何通過 MQTT 傳輸并使用 RabbitMQ 和 Spring-AMQP 在 AMQP 上接收的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

所以我已經(jīng)讓 MQTT -> MQTT 和 AMQP -> AMQP 工作了;MQTT -> AMQP 的翻譯似乎并沒有在某處工作.這是我的測試,如果我的監(jiān)聽器"也在使用 paho 的 MQTT 中,則它通過了,但是這個 rabbitmq 實(shí)現(xiàn)沒有.

So I've gotten MQTT -> MQTT and AMQP -> AMQP to work; the translation of MQTT -> AMQP doesn't seem to be working somewhere though. Here's my test, it passes if my "listener" is also in MQTT using paho, but this rabbitmq implementation doesn't.

@SpringBootTest
@SpringJUnitConfig
internal open class ProvisioningTest @Autowired constructor(
    private val mqtt: IMqttAsyncClient,
    private val mapper: ObjectMapper
) {

    @Test
    fun provision() {
        val entity = Foley(
            rfid = UUID.randomUUID().toString(),
        )

        val called = AtomicBoolean(false)
        mqtt.subscribe("foley/created", 1) { _, _ -> called.set(true) }

        mqtt.publish("foley/new", MqttMessage(mapper.writeValueAsBytes(entity)))

        Awaitility.await().atMost(10, TimeUnit.SECONDS).untilTrue(called)
    }
}

這是將保存的實(shí)體發(fā)布到另一個隊(duì)列的偵聽器;當(dāng)我發(fā)布到 MQTT 時,它永遠(yuǎn)不會被調(diào)用.

this is the listener that publishes the saved entity to the other queue; it never gets called when I publish to MQTT.

@Service
open class Provisioning(private val repo: FoleyRepo) {
    private val log: Logger = LogManager.getLogger(this::class.java)

    @SendTo("foley.created")
    @RabbitListener(queuesToDeclare = [Queue("foley.new")] )
    open fun listen(entity: Foley): Foley {
        log.trace("saving: {}", entity)
        val save = repo.save(entity)
        log.debug("saved: {}", save)
        return save
    }

}

我的全部消息配置

@Configuration
open class MessagingConfig {

    @Bean
    open fun client(
        @Value("tcp://${mqtt.client.host:localhost}:${mqtt.client.port:1883}") uri: String,
        @Value("${mqtt.client.user:#{null}}") user: String?,
        @Value("${mqtt.client.pass:#{null}}") pass: CharArray?
    ): IMqttAsyncClient {

        val connOpt = MqttConnectOptions()
        user?.let { connOpt.userName = it }
        pass?.let { connOpt.password = it }
        connOpt.isCleanSession = false
        connOpt.isAutomaticReconnect = true
        val client = MqttAsyncClient(uri, MqttAsyncClient.generateClientId(), MemoryPersistence())
        client.connect(connOpt)
        return client
    }

    @Bean
    open fun messageConverter( om: ObjectMapper): MessageConverter {
        return Jackson2JsonMessageConverter(om)
    }

    @Bean
    open fun builder(): Jackson2ObjectMapperBuilderCustomizer {
        return Jackson2ObjectMapperBuilderCustomizer {
            it.modules(JavaTimeModule(), KotlinModule())
        }
    }
}

使用啟用了 mqtt 的 官方 docker rabbitmq 映像.

using the official docker rabbitmq image with mqtt enabled.

我需要糾正什么才能完成這項(xiàng)工作?

What do I need to correct to make this work?

推薦答案

MQTT插件發(fā)布到amq.topic,以mqtt主題名作為路由key.

The MQTT plugin publishes to the amq.topic with the mqtt topic name as the routing key.

在消費(fèi)者端,它使用路由鍵將自動刪除隊(duì)列綁定到該交換;在以下示例中,隊(duì)列名為 mqtt-subscription-mqttConsumerqos1.

On the consumer side, it binds an auto-delete queue to that exchange, with the routing key; in the following example, the queue is named mqtt-subscription-mqttConsumerqos1.

為了通過 AMQP 接收 MQTT 消息,您需要將自己的隊(duì)列綁定到交換器.這是一個例子:

In order to receive MQTT messages over AMQP, you need to bind your own queue to the exchange. Here is an example:

@SpringBootApplication
public class So54995261Application {

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

    @Bean
    @ServiceActivator(inputChannel = "toMQTT")
    public MqttPahoMessageHandler sendIt(MqttPahoClientFactory clientFactory) {
        MqttPahoMessageHandler handler = new MqttPahoMessageHandler("clientId", clientFactory);
        handler.setAsync(true);
        handler.setDefaultTopic("so54995261");
        return handler;
    }

    @Bean
    public MqttPahoClientFactory mqttClientFactory() {
        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
        MqttConnectOptions options = new MqttConnectOptions();
        options.setServerURIs(new String[] { "tcp://localhost:1883" });
        options.setUserName("guest");
        options.setPassword("guest".toCharArray());
        factory.setConnectionOptions(options);
        return factory;
    }

    @Bean
    public MessageProducerSupport mqttInbound() {
        MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("mqttConsumer",
                mqttClientFactory(), "so54995261");
        adapter.setCompletionTimeout(5000);
        return adapter;
    }

    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows.from(mqttInbound())
                .handle(System.out::println)
                .get();
    }

    @RabbitListener(queues = "so54995261")
    public void listen(byte[] in) {
        System.out.println(new String(in));
    }

    @Bean
    public Queue queue() {
        return new Queue("so54995261");
    }

    @Bean
    public Binding binding() {
        return new Binding("so54995261", DestinationType.QUEUE, "amq.topic", "so54995261", null);
    }

    @Bean
    public ApplicationRunner runner(MessageChannel toMQTT) {
        return args -> toMQTT.send(new GenericMessage<>("foo"));
    }

}

這篇關(guān)于如何通過 MQTT 傳輸并使用 RabbitMQ 和 Spring-AMQP 在 AMQP 上接收的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 国产大学生情侣呻吟视频 | 亚洲一区在线日韩在线深爱 | 精品国产乱码久久久久久闺蜜 | www.国产.com| 天天插日日操 | 国产黄色免费网站 | 最新日韩av | 亚洲一区 中文字幕 | 成人午夜在线 | 国产资源一区二区三区 | 欧美激情久久久 | 亚洲精品一区二区三区中文字幕 | 国产高清一区二区三区 | 99久久精品免费看国产四区 | 久久久久99 | 一区二区高清不卡 | 午夜看看 | 懂色一区二区三区免费观看 | 欧美一区二区三区四区在线 | 一区在线视频 | 国产福利资源在线 | av免费网址 | 国产精品久久久久久婷婷天堂 | 欧美啊v在线观看 | 亚洲精品播放 | 一区二区三区欧美在线观看 | 日韩精品一区二区三区中文在线 | 青青草一区 | 一区二区三区视频在线观看 | 免费精品视频一区 | 国产精品福利视频 | 国产成人免费视频网站高清观看视频 | 日本久久精品视频 | 欧美精产国品一二三区 | 精精国产xxxx视频在线野外 | 欧美精品片 | 日韩成年人视频在线 | 97精品久久 | 国产高清在线视频 | 精品亚洲一区二区三区 | 精品一区国产 |