Spring 启动 JMS:通过 (RxJava) 订阅访问 receiveMessage() 结果?
Spring Boot JMS: access receiveMessage() result via a (RxJava) subscription?
如何访问 JMS 消息回执,例如'receiveMessage( )' 像 RxJava 订阅一样?
我不想以回调方式执行此操作。我想对调用者隐藏实现的细节,比如@JmsListener。
例如,当 JMS 队列中有可用消息时,我会调用一个典型的方法。
@JmsListener(destination = "mailbox", containerFactory = "myFactory")
public void receiveMessage(Email email) {
logger.info("Received <" + email + ">");
}
如何通过 (RxJava) 订阅访问可用消息?
receiver.subscribe( message -> { ... });
只需使用 RxJava 主题。我知道 Observables 好一点。
PublishSubject<String> source; = PublishSubject.create();
public PublishSubject<String> getMessages() {
source = PublishSubject.create();
return source;
}
@JmsListener(destination = "mailbox", containerFactory = "myFactory")
public void receiveMessage(Email email) {
logger.info("Received <" + email + ">");
source.onNext( email.getmessage());
}
给消费者主题。它可以调用:
source.subscribe( f -> System.out.println( "Subscriber1: " + f));
如何访问 JMS 消息回执,例如'receiveMessage( )' 像 RxJava 订阅一样?
我不想以回调方式执行此操作。我想对调用者隐藏实现的细节,比如@JmsListener。
例如,当 JMS 队列中有可用消息时,我会调用一个典型的方法。
@JmsListener(destination = "mailbox", containerFactory = "myFactory")
public void receiveMessage(Email email) {
logger.info("Received <" + email + ">");
}
如何通过 (RxJava) 订阅访问可用消息?
receiver.subscribe( message -> { ... });
只需使用 RxJava 主题。我知道 Observables 好一点。
PublishSubject<String> source; = PublishSubject.create();
public PublishSubject<String> getMessages() {
source = PublishSubject.create();
return source;
}
@JmsListener(destination = "mailbox", containerFactory = "myFactory")
public void receiveMessage(Email email) {
logger.info("Received <" + email + ">");
source.onNext( email.getmessage());
}
给消费者主题。它可以调用:
source.subscribe( f -> System.out.println( "Subscriber1: " + f));