【问题标题】:ActiveMQ compositeTopic's selective persistenceActiveMQ 复合主题的选择性持久化
【发布时间】:2016-05-29 13:54:39
【问题描述】:

我正在使用 ActiveMQ 的 compositeTopic 将消息扇出到多个目的地,如下所示:

<broker>
    <persistenceAdapter>
        <kahaDB directory="${activemq.data}/kahadb"/>
    </persistenceAdapter>

    ...

    <destinationInterceptors>
        <virtualDestinationInterceptor>
            <virtualDestinations>
                <compositeTopic name="fan-out" forwardOnly="true">
                    <forwardTo>
                        <queue physicalName="persistent"/>
                        <queue physicalName="ephemeral"/>
                    </forwardTo>
                </compositeTopic>
            </virtualDestinations>
        </virtualDestinationInterceptor>
    </destinationInterceptors>
</broker>

所以,我想同时将消息转发到persistentephemeral 队列。正如您可能从他们的名字中猜到的那样,我希望persistent 队列中的消息是持久的,而我不需要ephemeral 队列的持久性。问题是 ActiveMQ 没有基于每个目标的持久性概念,是吗?可以为整个代理设置持久性,或使用持久性/非持久性交付模式。所以,问题是:在这种情况下,如何禁用 ephemeral 队列的持久性?

【问题讨论】:

  • 基于此page,您似乎是正确的:“对于使用setDeliveryMode 的所有消息,在MessageProducer 上设置了持久性标志。也可以在每条消息上指定它使用长格式的 send 方法的基础。持久性是单个消息的属性。"

标签: java jms persistence activemq


【解决方案1】:

因此,似乎可行的解决方案是将 Apache Camel 与 ActiveMQ 结合使用。只需添加一个将ephemeral 队列排空的路由到另一个队列设置 TTL / 持久化模式:

<broker>
    <persistenceAdapter>
        <kahaDB directory="${activemq.data}/kahadb"/>
    </persistenceAdapter>

    ...

    <destinationInterceptors>
        <virtualDestinationInterceptor>
            <virtualDestinations>
                <compositeTopic name="fan-out" forwardOnly="true">
                    <forwardTo>
                        <queue physicalName="persistent"/>
                        <queue physicalName="ephemeral"/>
                    </forwardTo>
                </compositeTopic>
            </virtualDestinations>
        </virtualDestinationInterceptor>
    </destinationInterceptors>
</broker>

<camelContext xmlns="http://camel.apache.org/schema/spring" id="camel">
    <route>
        <from uri="activemq:queue:ephemeral"/>
        <to uri="activemq:queue:ephemeral-backend?timeToLive=10000"/>
    </route>
</camelContext>

timeToLive 是消息的 TTL,以毫秒为单位。在上面的配置中,消息仍然是持久的:在 TTL 到期后,它们被移动到DLQ。如果你想扔掉它们,那么配置应该包括 deliveryPersistent 设置为 false:

<camelContext xmlns="http://camel.apache.org/schema/spring" id="camel">
  <route>
    <from uri="activemq:queue:ephemeral" />
    <to uri="activemq:queue:ephemeral-backend?timeToLive=10000&amp;deliveryPersistent=false" />
  </route>
</camelContext>

【讨论】:

    猜你喜欢
    • 2012-02-08
    • 2015-06-16
    • 2011-05-29
    • 2015-11-28
    • 2015-01-21
    • 2011-04-26
    • 2016-04-27
    • 2012-05-22
    • 2015-08-22
    相关资源
    最近更新 更多