wildfly 10,JMS,MDB,主题没有收到消息

时间:2016-06-05 11:03:35

标签: jms activemq message-driven-bean jms-topic wildfly-10

我有两个消息驱动的bean

@MessageDriven(name = "SubscribersTopicQueueMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/topic/Subscribers"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class SubscribersTopicQueueMDB implements MessageListener {

    private final static Logger LOGGER = Logger.getLogger(SubscribersTopicQueueMDB.class.toString());

    public SubscribersTopicQueueMDB() {
        System.out.println("Topic: SubscribersTopicQueueMDB  INIT ");
    }

and
@MessageDriven(name = "SubscribersTopicSecondMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/topic/Subscriber"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class SubscribersTopicSecondMDB implements MessageListener {

    private final static Logger LOGGER = Logger.getLogger(SubscribersTopicSecondMDB.class.toString());

    public SubscribersTopicSecondMDB() {
         System.out.println("TOPIC: SubscribersTopicSecondMDB (Second)  INIT ");
    }

当我向主题jms / topic / Subscriber发送消息时,仅收到第一个MDB消息,第二个MDB不接收任何消息。 我怎样才能改善这个?

我的简单客户

public static void sendTextMessage(String message, String passedDestination) {
        if (message == null || passedDestination == null) {
            return;
        }
        Context namingContext = null;

        try {
            String userName = JMS_DEFAULT_USERNAME;
            String password = JMS_DEFAULT_PASSWORD;
            // Set up the namingContext for the JNDI lookup
            final Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, JMS_INITIAL_CONTEXT_FACTORY);
            env.put(Context.PROVIDER_URL, JMS_PROVIDER_URL);
            // env.put(Context.SECURITY_PRINCIPAL, userName);
            // env.put(Context.SECURITY_CREDENTIALS, password);
            namingContext = new InitialContext(env);
            // Perform the JNDI lookups
            String connectionFactoryString = JMS_DEFAULT_CONNECTION_FACTORY;
            System.out.println("+@@Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
            ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
            System.out.println("+@@@Found connection factory \"" + connectionFactoryString + "\" in JNDI " + connectionFactory.toString());

            String destinationString = passedDestination;
            System.out.println("+@@Attempting to acquire destination \"" + destinationString + "\"");
            Destination destination = (Destination) namingContext.lookup(destinationString);
            System.out.println("+@@@Found destination \"" + destinationString + "\" in JNDI");

            int count = 2;
            String content = message;
            //System.out.println("userName " + userName);
            //System.out.println("password " + password);
            try (JMSContext context = connectionFactory.createContext()) {
                System.out.println("***************Sending to  " + destinationString + " messages with content: " + content + " *********************");
                 context.createProducer().send(destination, content);

            }
            //return true;
        } catch (NamingException e) {
            e.printStackTrace();
        } finally {
            if (namingContext != null) {
                try {
                    namingContext.close();
                } catch (NamingException e) {
                    e.printStackTrace();
                }
            }
            // return false;
        }

1 个答案:

答案 0 :(得分:0)

发现我的错误一个主题听jms / topic / Subscriber第二个jms / topic / Subscribers.improved。