gpt4 book ai didi

使用 ActiveMQ 的 Quarkus?

转载 作者:行者123 更新时间:2023-12-04 01:44:44 25 4
gpt4 key购买 nike

在与 Kafka 一起试用 Quarkus 之后,我想知道
如何将它与 ActiveMQ 一起使用。我无法
查找任何文档。 Quarkus.io 提到了对 amqp 协议(protocol)的支持。

有人知道如何实现这一目标吗?

最佳答案

除了@John Clingan(谢谢!)直接使用 VertX 提供的答案之外,您还可以使用 microprofile-reactive-messaging:

  • smallrye amqp 扩展的当前版本 (0.0.7) 不适用于 Quarkus(CDI 没有空构造函数)。修复程序已经在主分支中。
  • git clone https://github.com/smallrye/smallrye-reactive-messaging.git
    cd smallrye-reactive-messaging
    mvn install
  • 将新建的工件添加到您的 pom
  • <dependency>
    <groupId>io.smallrye.reactive</groupId>
    <artifactId>smallrye-reactive-messaging-amqp</artifactId>
    <version>0.0.8-SNAPSHOT</version>
    </dependency>
  • 在 application.properties
  • 中配置 amqp
    # amqp output
    smallrye.messaging.sink.my-amqp-output.type=io.smallrye.reactive.messaging.amqp.Amqp
    smallrye.messaging.sink.my-amqp-output.address=test-activemq-amqp
    smallrye.messaging.sink.my-amqp-output.containerId=test-activemq-clientid
    smallrye.messaging.sink.my-amqp-output.host=localhost

    # amqp input
    smallrye.messaging.source.my-amqp-input.type=io.smallrye.reactive.messaging.amqp.Amqp
    smallrye.messaging.source.my-amqp-input.address=test-activemq-amqp
    smallrye.messaging.source.my-amqp-input.containerId=test-activemq-clientid
    smallrye.messaging.source.my-amqp-input.host=localhost
  • 使用 microprofile-reactive-messaging

  • 3.1 从 rest servlet 发送消息
    @Path("/hello")
    public class HelloWorldResource {

    @Inject
    @Stream("my-amqp-output")
    Emitter<String> emitter;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
    emitter.send("hello!");
    return "hello send";
    }
    }


    3.2 接收消息
    @ApplicationScoped
    public class AmqpReceiver {

    @Incoming("my-amqp-input")
    public void receive(String input) {
    //process message
    }
    }

    使用 quarkus 0.14.0 和 0.13.3 进行测试。

    关于使用 ActiveMQ 的 Quarkus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55782716/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com