Skip to content

Commit

Permalink
fix(selector): Add getter to use listener externally (#68)
Browse files Browse the repository at this point in the history
* fix(selector): Add getter to use listener externally

* fix(selector): Add requestReply with specific queue

* fix(selector): Add requestReply with specific queue
  • Loading branch information
maocq authored Aug 1, 2024
1 parent b2e14c9 commit e70f313
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import jakarta.jms.Destination;
import jakarta.jms.Message;
import jakarta.jms.Queue;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import reactor.core.publisher.Mono;

import java.time.Duration;

@Getter
@Log4j2
public abstract class AbstractMQRequestReplyListener<T> extends MQMessageListenerRetries {
public static final int SECONDS_TIMEOUT = 30;
Expand Down Expand Up @@ -51,6 +53,10 @@ public Mono<T> requestReply(MQMessageCreator messageCreator, Duration timeout) {
return sender.send(requestQueue, messageCreator).flatMap(id -> router.wait(id, timeout));
}

public Mono<T> requestReply(String message, Destination request, Duration timeout) {
return sender.send(request, defaultCreator(message)).flatMap(id -> router.wait(id, timeout));
}

private MQMessageCreator defaultCreator(String message) {
return ctx -> {
Message jmsMessage = ctx.createTextMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public Mono<Message> requestReply(MQMessageCreator messageCreator, Duration time
container.get(replyQueue)));
}

public Mono<Message> requestReply(String message, Destination request, Destination reply, Duration timeout) {
return sender.send(request, defaultCreator(message))
.flatMap(id -> listener.getMessageBySelector(selector.buildSelector(id), timeout.toMillis(), reply));
}

private MQMessageCreator defaultCreator(String message) {
return ctx -> {
Message jmsMessage = ctx.createTextMessage(message);
Expand Down

0 comments on commit e70f313

Please sign in to comment.