spring-boot - Solace 中的 ConsumerFlowProperties 是否会延续?

标签 spring-boot spring-jms solace

我正在审查安慰应用程序的代码库。这里,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/

相关文章:

spring-boot - 在 Spring Boot 中自定义 JSON 响应以更改键名

java - Spring的@JmsListener只从Solace队列接收一条消息

ssl - Solace 客户端身份验证给出不受信任的证书错误(响应代码 : 401)

java - 如何通过 AWS Parameter Store Spring 属性源的 Java 属性公开 AWS 凭证

java - Spring Boot执行器关闭不会终止无限循环

spring-boot - 编写测试来验证 jms 监听器中收到的消息(Spring-Boot)

activemq - 正确关闭 ActiveMQ 和 Spring DefaultMessageListenerContainer

spring-jms - Solace 集成方法 Apache Qpid JMS 客户端(非 Solace JMS API)或 Solace JMS API

spring - 使用哪个 spring 事务隔离级别来维护已售产品的计数器?

java - Spring 集成 : Not able to send the message to channel