IBM MQ主题查找始终返回默认目标

时间:2016-02-03 13:04:20

标签: java jms ibm-mq

问题陈述:

我们在开发队列管理器(USTCMN01)上设置了2个主题

一个用于我们的开发用途(EDM.BIRS.RDP.ONEPPM.TO_RDA),另一个用于SIT(EDM.BIRS.RDP.S1.ONEPPM.TO_RDA)

发布到我们的SIT主题时,我们的消费者队列(EDM.BIRS.RDP.S1.RDA.FROM_ONEPPM)没有在另一端收到消息。 在制作信息时我们没有得到任何例外。

问题:

当我们尝试在Java客户端中查找SIT主题时,尽管我们正在提供专用于SIT的目的地,但它正在解析为DEV主题。

IBM MQ基础架构由不同的团队处理

Java客户端代码

附件中的例程produceWorkflowMessage()负责发布消息

package com.cs.srp.rdp.omb;

import org.apache.bcel.classfile.ConstantClass;

 import javax.jms.*;
 import javax.naming.InitialContext;
 import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManagerFactory;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.security.KeyStore;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List; 
 import java.util.Properties;

 import static javax.naming.Context.*;

 public class OMBTopicPublisher {


private InitialContext ic = null;
private Connection connection;
private Session session;
ConnectionFactory connectionFactory;

private Connection createConnection() throws JMSException {
    String providerCredentials = "aGMk643R";
    String providerUrl = "ldap://esd-qa.csfb.net/ou=MQ,ou=Services,dc=csfb,dc=CS-Group,dc=com";
    String keyStoreFile = "C:\\Balaji\\workspace\\workflowrda\\src\\main\\properties\\jks\\test\\keystore.jks";
    String password = "rFzv0UOS";
    String queueManagerConnectionFactory = "cn=USTCMN01_CF";
    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(new FileInputStream(keyStoreFile), password.toCharArray());

        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(keyStore, password.toCharArray());

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(keyStore);

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        SSLContext.setDefault(sslContext);

        Hashtable<String, String> hashTable = new Hashtable<>();
        hashTable.put(PROVIDER_URL, providerUrl);
        hashTable.put(INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        hashTable.put(SECURITY_AUTHENTICATION, "simple");
        hashTable.put(SECURITY_PRINCIPAL, "uid=MQRDP,ou=People,o=Administrators,dc=CS-Group,dc=com");
        hashTable.put(SECURITY_CREDENTIALS, providerCredentials);

        ic = new InitialContext(hashTable);
        connectionFactory = (ConnectionFactory) ic.lookup(queueManagerConnectionFactory);
        connection = connectionFactory.createConnection();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        System.out.println("Exception while trying to connect to DEV OMB queue");
    }
    return connection;
}

private Session createSession() throws JMSException {
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    return session;
}

private void init() throws JMSException {
    createConnection();
    createSession();
}

public void produceWorkflowMessage(String inboundControlMessageXML) throws JMSException {
    init();
    String destinationStr = "EDM.BIRS.RDP.S1.ONEPPM.TO_RDA";
    MessageProducer producer;
    Destination destination;
    try {
        destination = (Destination) ic.lookup("cn=" + destinationStr);
        TextMessage message = session.createTextMessage(inboundControlMessageXML);
        producer = session.createProducer(destination);
        producer.send(message);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        System.out.println("Exception occured while posting message to OMB topic");
        System.exit(1);
    } finally {
        session.close();
        connection.close();
    }
}

public static List<String> loadFromPropertiesFile(String propFileName) {
    InputStream inputStream = null;
    List<String> workflowMessageList = null;
    try {
        Properties workflowProperties = new Properties();
        inputStream = ConstantClass.class.getClassLoader().getResourceAsStream(propFileName);
        if (inputStream != null) {
            workflowProperties.load(inputStream);
        } else {
            throw new FileNotFoundException("property file '"
                    + propFileName + "' not found in the classpath");
        }
        workflowMessageList = new ArrayList<String>();
        for (String key : workflowProperties.stringPropertyNames()) {
            System.out.println("Key =" + key);
            String value = workflowProperties.getProperty(key);
            workflowMessageList.add(value);
        }

    } catch (Exception e) {
        System.out.println("Error loading inboundxml worflow messages from properties file: " + e);
    } finally {
        try {
            inputStream.close();
        } catch (IOException ioe) {
            System.out
                    .println("Exception while closing the file stream");
        }
    }
    return workflowMessageList;
}

}

2 个答案:

答案 0 :(得分:0)

这段代码:

String destinationStr = "EDM.BIRS.RDP.S1.ONEPPM.TO_RDA";

Destination destination;
try {
    destination = (Destination) ic.lookup("cn=" + destinationStr);

从JNDI查找JMS Destination对象;在这种情况下,您已将其配置为LDAP支持的JNDI。请注意,提供的名称是正在使用的查找名称或队列索引Java对象。返回的实际Destination将控制控制该LDAP / JNDI服务器的任何人。

对目标对象执行.toString()并查看要解析的内容。这实际上就是发送消息的地方。

请注意,从JNDI查找对象所提供的名称不是要使用的队列或主题的实际名称。

答案 1 :(得分:0)

问题是由于LDAP服务器中的外部配置不匹配导致返回的目标值不同。