问题
After trying out Quarkus with Kafka I‘m wondering how to use it with ActiveMQ. I was not able to find any documentation. Quarkus.io mentions support for amqp protocoll.
Does somebody know how to achieve this?
回答1:
Additionally to the answer provided by @John Clingan (Thanks!) to use VertX directly, you can also use microprofile-reactive-messaging:
- The current version (0.0.7) of the smallrye amqp extension does not work with Quarkus (No empty Constructor for CDI). A fix is already in the master branch.
git clone https://github.com/smallrye/smallrye-reactive-messaging.git
cd smallrye-reactive-messaging
mvn install
- Add the newly built artifact to your pom
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-amqp</artifactId>
<version>0.0.8-SNAPSHOT</version>
</dependency>
- Configure amqp in application.properties
# 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
- Use microprofile-reactive-messaging
3.1 Sending messages from a 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 Receiving messages
@ApplicationScoped
public class AmqpReceiver {
@Incoming("my-amqp-input")
public void receive(String input) {
//process message
}
}
Tested with quarkus 0.14.0 and 0.13.3.
来源:https://stackoverflow.com/questions/55782716/quarkus-with-activemq