在部署时更改主题读取MDB的激活配置 [英] Changing Activation Config of Topic reading MDB at deploy time

查看:202
本文介绍了在部署时更改主题读取MDB的激活配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这应该很容易。只是RTM然后去。但我找不到我需要的信息。

I feel this should be easy. Just RTM and go. But I can't find the info I need.

问:我可以更改 @ActivationConfigProperty的值在部署时无需编写任何XML?

Q: Can I change the value of an @ActivationConfigProperty at deploy time without having to write any XML?

我有一个使用 @MessageDriven 注释的MDB。其中有一些 @ActivationConfigProperty 注释配置它。

I have an MDB which is using the @MessageDriven annotation. Within this are a number of @ActivationConfigProperty annotations configuring it.

@MessageDriven(mappedName = "jms/TestJeremyTopic ", activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
        @ActivationConfigProperty(propertyName = "clientId", propertyValue = "TopicReaderBeanClientId"),
        @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "TopicReaderBeanSubscriptionName")
})
public class TopicReaderBean implements MessageListener { // ...

我需要多次部署此MDB,每次都会引用不同的主题。

I need to deploy this MDB multiple times, referring to a different topic each time.

在部署时(WebSphere 7 N. D)我能够为每个EAR配置不同的 TopicListenerPort (WebSphere的映射到不同主题的方式)。但是,当我尝试启动第二个实例时,它失败并显示错误:

At deploy time (WebSphere 7 ND) I am able to configure a distinct TopicListenerPort (WebSphere's way of mapping to different topics) for each EAR. However when I try to start a second instance it fails with the error:


WMSG0019E:无法启动MDB侦听器TopicReaderBean,JMSDestination jms / MMiSInLonTopic :com.ibm.msg.client.jms.DetailedIllegalStateException:JMSWMQ0026:无法使用MQSUB订阅主题MMIS_LON_IN。由于其被另一个消息使用者使用,因此可能存在创建订阅的问题。在尝试使用相同名称创建新订阅之前,请确保使用此订阅的任何消息使用者都已关闭。有关详细信息,请参阅链接的例外。
引起:com.ibm.mq.MQException:JMSCMQ0001:WebSphere MQ调用失败,compcode为'2'('MQCC_FAILED')原因'2429'('MQRC_SUBSCRIPTION_IN_USE')。

WMSG0019E: Unable to start MDB Listener TopicReaderBean, JMSDestination jms/MMiSInLonTopic : com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0026: Failed to subscribe to topic 'MMIS_LON_IN' using MQSUB. There may have been a problem creating the subscription due to it being used by another message consumer. Make sure any message consumers using this subscription are closed before trying to create a new subscription under the same name. Please see the linked exception for more information. Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2429' ('MQRC_SUBSCRIPTION_IN_USE').

当我查看MQ Explorer时,我可以看到订阅名称是 JMS:GGWKNNG5:gmm_poc_06:TopicReaderBeanSubscriptionName 这是一个JMS,QueueManager名称,主题连接工厂ID和ActivationConfigPropertysubscriptionName的组合。第二个连接因此订阅名称发生冲突而失败。我需要区分不同MDB实例使用的订阅名称。

When I look to MQ Explorer I can see the subscription name is JMS:GGWKNNG5:gmm_poc_06:TopicReaderBeanSubscriptionName This is a composition of "JMS", QueueManager name, Topic Connection Factory ID, and ActivationConfigProperty "subscriptionName". The second connection fails because of a clash on this subscription name. I need to distinguish the subscription names used by distinct MDB instances.

虽然我可以为每个bean创建一个新的主题连接工厂,但这将是很多工作并且不会没有多大意义。

Whilst I could create a new Topic Connection Factory for each bean, it would be a lot of work and doesn't make much sense.

有意义的是每个bean有一个不同的订阅名称。但是这个属性被添加到注释中,我无法在WebSphere中看到允许我覆盖它的任何地方。

What does make sense is to have a different subscription name per bean. However this property is baked into the annotation and I can't see anywhere in WebSphere that would allow me to override it.

因此,我可以覆盖此属性而不必编写XML部署描述符?如果我需要编写一些XML,我该如何覆盖其中的属性?

So, can I override this property without having to write an XML deployment descriptor? And if I do need to write some XML, how do I override the property therein?

推荐答案

代替任何部署时解决方案,我编写了一个 ejb-jar.xml 配置,我可以在构建时修改它。它如下所示:

In lieu of any deploy-time solution I've written an ejb-jar.xml config that I can modify at build time. It reads thus:

<?xml version="1.0"?>
 <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
      version="3.1">
    <enterprise-beans>

        <message-driven id="MySpecialMDB">
            <display-name>MySpecialMDB</display-name>
            <ejb-name>TopicReaderBean</ejb-name>
            <ejb-class>my.TopicReaderBean</ejb-class>
            <transaction-type>Container</transaction-type>
            <message-destination-type>javax.jms.Topic</message-destination-type>
            <activation-config>
                <activation-config-property>
                    <activation-config-property-name>destinationType</activation-config-property-name>
                    <activation-config-property-value>javax.jms.Topic</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                    <activation-config-property-name>subscriptionDurability</activation-config-property-name>
                    <activation-config-property-value>Durable</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                    <activation-config-property-name>subscriptionName</activation-config-property-name>
                    <activation-config-property-value>${subscriptionName}</activation-config-property-value>
                </activation-config-property>
            </activation-config>
        </message-driven>

    </enterprise-beans>
</ejb-jar>

这篇关于在部署时更改主题读取MDB的激活配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆