我正在审查安慰应用程序的代码库。这里,FlowReceiver 配置有 ConsumerFlowProperties,以从队列的开头重播。然后 FlowReceiver 启动和停止, session 关闭,根本不读取任何消息。然后在最后,它启动与事件关联的 ListenerContainer,该容器由使用 @JmsListener 注释的方法使用。但为什么 ConsumerFlowProperties 会保留下来呢?为什么它从一开始就重放安慰队列中存在的所有消息?这些属性不应该与之前的 session /使用者关联吗?
public void replayThenStart() {
final var jcsmpFactory = JCSMPFactory.onlyInstance();
JCSMPSession session = null;
try {
session = jcsmpFactory.createSession(jcsmpProperties);
session.connect();
final var queue = jcsmpFactory.createQueue("q/uat/event");
final var consumerFlowProperties = new ConsumerFlowProperties();
consumerFlowProperties.setEndpoint(queue);
consumerFlowProperties.setReplayStartLocation(jcsmpFactory.createReplayStartLocationBeginning());
consumerFlowProperties.setActiveFlowIndication(false);
FlowReceiver consumer = null;
try {
consumer = session.createFlow(this, consumerFlowProperties);
consumer.start();
log.info("Replay flow (" + consumer + ") created.");
} catch (Throwable t) {
log.error("Failed replay flow.", t);
} finally {
if (consumer != null) {
log.info("Close replay flow.");
consumer.close();
}
}
} catch (Throwable t) {
log.error("Failed replay session.", t);
} finally {
if (session != null) {
session.closeSession();
}
}
Objects.requireNonNull(jmsListenerEndpointRegistry.getListenerContainer("eventListener")).start();
}
@JmsListener(id = "eventListener", destination = "q/uat/event", containerFactory = "eventContainerFactory")
public void onEvents(final List<Event> events, @Header("authentication") final String header) {
try {
onEvents(events, jwtUtil.getAuthentication(header));
} catch (Throwable e) {
log.error("Failed authenticating header [{}].", header, e);
log.debug("Unable to retrieve events - [{}]", events);
}
}
public void onEvents (final List<Event> events, final Authentication authentication) {
//process events
}
最佳答案
在我看来,他们想使用 JMS 来使用事件,但他们也想使用 Solace 的重播功能。由于这不是 JMS 功能,因此他们使用 Solace 的 JCSMP API 来触发重播。
因此,他们正在设置 JMS 使用者来监听队列,这是代理上的持久端点。然后使用 JCSMP 表示“将事件重播到该队列”。队列本身是消息重播并驻留在代理上的地方,而 ConsumerFlow 正是您的应用程序绑定(bind)到该队列的方式。 Solace 文档中的一些图表应该有助于描述这一点:https://docs.solace.com/API/Component-Maps.htm#SMF
关于spring-boot - Solace 中的 ConsumerFlowProperties 是否会延续?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76666897/