Java Quarkus smallrye-amqp queue - stream messages from queue on endpoint

Viewed 20

I have two projects A and B. A posts messages to a queue. B reads messages from a queue. B also wants to stream these messages to /messages

Project A sends a messages like this

@ApplicationScoped
public class MessageProducer {
    
    @Inject
    @Channel("message-response")
    Emitter<String> emitter;

    public void send() {
        Message<String> message = Message.of("hello message", Metadata.of(OutgoingAmqpMetadata.builder().withUserId("message-service").withCreationTime(System.currentTimeMillis()).build()));
        emitter.send(message);
    }
}

project A application properties

mp.messaging.outgoing.message-response.connector=smallrye-amqp
mp.messaging.outgoing.message-response.address=message.response
mp.messaging.outgoing.message-response.durable=true

and this works i can see the message in the queue through the acitveMQ GUI

in project B however, things does not work. I have exposed the messages as follows


@Path("/")
public class MessageResource{

    @Inject
    @Channel("response") Multi<String> messageRequest;
    
    @GET
    @Path("/messages")
    @Produces(MediaType.SERVER_SENT_EVENTS) 
    public Multi<String> stream() {
        return messageRequest;
    }
}


@ApplicationScoped
public class messageProcessor {

    @Incoming("message-response")       
    @Outgoing("response")         
    @Blocking                   
    public String process(String message) throws InterruptedException {
        // simulate some hard-working task
        System.out.println(message); // this prints the message from project A
        Thread.sleep(200);
        return message;
    }
}

project B application.prop

mp.messaging.incoming.message-response.connector=smallrye-amqp
mp.messaging.incoming.message-response.address=message.response
mp.messaging.incoming.message-response.durable=true
mp.messaging.incoming.message-response.failure-strategy=modified-failed

When I use postman to GET localhost:8080/messages it connects to the stream but nothing is being printed

0 Answers
Related