I am reviewing the codebase of a solace application. Here a FlowReceiver is configured with a ConsumerFlowProperties to replay from the start of a queue. Then the FlowReceiver is started and stopped, and the session is closed without reading any messages at all. Then at the very end, it starts the ListenerContainer associated with the Events', which is being used by a method annotated with @JmsListener. But why does the ConsumerFlowProperties carry over? Why is it replaying from the very start all the messages that exist in the solace queue? Shouldnt the properties be associated with the previous session/consumer?
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
}