3

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

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

4

1 回答 1

4

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

  1. smallrye amqp 扩展的当前版本 (0.0.7) 不适用于 Quarkus(CDI 没有空构造函数)。修复程序已经在主分支中。
git clone https://github.com/smallrye/smallrye-reactive-messaging.git
cd smallrye-reactive-messaging
mvn install
  1. 将新建的工件添加到您的 pom
<dependency>
   <groupId>io.smallrye.reactive</groupId>
   <artifactId>smallrye-reactive-messaging-amqp</artifactId>
   <version>0.0.8-SNAPSHOT</version>
</dependency>
  1. 在 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
  1. 使用 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 进行测试。

于 2019-04-27T21:49:35.893 回答