2014-02-11 5 views
0

Я начинаю программировать в веб-сфере mq.Для учебника Websphere MQ

У любого есть пример учебника для подключения очереди mq к простому приложению Java.

В основном я хочу прочитать очередь Mq через мой код Java.

Пожалуйста, помогите мне.

Заранее спасибо

ответ

3

Ваш RC = 2538, потому что у вас есть ошибки кодирования, и я уже указал на это в ваш другой вопрос на MQJE001: Completion Code '2', Reason '2538'

Во-вторых, есть 34 Java/MQ (не JMS) образцы программ MQ на http://www.capitalware.biz/mq_code_java.html

Вы просмотрели их и/или попробовали их?

+0

ЮППЫ .. Я также попробовать этот code.Now я получил эту ошибку = «2539 (09EB) (RC2539): MQRC_CHANNEL_CONFIG_ERROR» Я пробовал много, но 2538 и 2539 ошибку пришедшего поэтому мне нужна помощь , Thnaks снова за предоставленное ур ценное время для меня –

+0

Вы смогли исправить эту проблему ?? – Bharathi

3

Я нахожу этот учебник и код на сайте jboss. Он работает также. Попробуйте this и наслаждайтесь.

public class WebSphereMQMessageSendServiceBean implements MessageSendService { 


    private static Logger logger = Logger.getLogger(WebSphereMQMessageSendServiceBean.class); 
    private Connection connection = null; 
    private Session session = null; 
    private MessageProducer producer = null; 


    public boolean sendMessage(String xmlMsg, String instrumentId) throws QueueServiceAdaptorException{ 
     boolean success = false;   
     String destinationType = "QUEUE"; 
     String destinationName = "PRO.QDX.QDX.MSG.QDC"; 
     String channel = "PROQDIB.SVRCONN"; 
     String hostName = "localhost"; 
     Integer port = "1414"; 
     String queueManager = "REFDMQ01"; 
     String uid = "nuwan"; 
     String provider = "com.ibm.msg.client.wmq"; 
     try { 
      JmsFactoryFactory jmsFactoryFactory = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER); 
      JmsConnectionFactory jmsConnectionFactory = jmsFactoryFactory.createConnectionFactory(); 
      // Set the properties 
      jmsConnectionFactory.setStringProperty(WMQConstants.WMQ_HOST_NAME, hostName); 
      jmsConnectionFactory.setIntProperty(WMQConstants.WMQ_PORT, port); 
      jmsConnectionFactory.setStringProperty(WMQConstants.WMQ_CHANNEL, channel); 
      jmsConnectionFactory.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT); 
      jmsConnectionFactory.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, queueManager);  


      // Create JMS objects 
      connection = jmsConnectionFactory.createConnection(); 
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
      Destination destination = null; 
      if (destinationType.equals("QUEUE")) { 
       destination = session.createQueue(destinationName); 
      } 
      else { 
       destination = session.createTopic(destinationName); 
      } 
      producer = session.createProducer(destination); 
      //connection.setExceptionListener(this); 
      connection.start(); 
      TextMessage message = session.createTextMessage(); 
      // If WMQ_MESSAGE_BODY is set to WMQ_MESSAGE_BODY_MQ, no additional header is added to the message body. 
      ((MQDestination) destination).setMessageBodyStyle(WMQConstants.WMQ_MESSAGE_BODY_MQ); 
      ((MQDestination)destination).setMQMDWriteEnabled(true);    
      message.setText(xmlMsg); 
      message.setJMSCorrelationID(instrumentId); 
      producer.send(message); 
      success = true; 
      logger.info("WebSphereMQMessageSender.sendMessage: Sent message:\n" + message); 
     } 
     catch (JMSException e) { 
      logger.error("WebSphereMQMessageSender.sendMessage: JMSException while sending message to QDIB", e); 
      success = false; 
      recordFailure(e); 
      throw new QueueServiceAdaptorException("WebSphereMQMessageSender.sendMessage: " 
        + "JMSException while sending message to QDIB", e); 
     } 
     catch (Exception e) { 
      logger.error("WebSphereMQMessageSender.sendMessage: Exception while sending message to QDIB", e); 
      success = false; 
      throw new QueueServiceAdaptorException("WebSphereMQMessageSender.sendMessage: " 
        + "Exception while sending message to QDIB", e); 
     } 
     finally { 
      cleanUp(); 
     } 
     return success; 
    } 


    /** 
    * Record this run as failure. 
    * 
    * @param ex exception 
    */ 
    private void recordFailure(Exception ex) { 
     if (ex != null) { 
      if (ex instanceof JMSException) { 
       processJMSException((JMSException) ex); 
      } else { 
       logger.error("WebSphereMQMessageSender.recordFailure: " + ex); 
      } 
     } 
     logger.error("WebSphereMQMessageSender.recordFailure: FAILURE");   
    } 


    /** 
    * Process a JMSException and any associated inner exceptions. 
    * 
    * @param jmsex jmsex 
    */ 
    private void processJMSException(JMSException jmsex) { 
     logger.error(jmsex); 
     Throwable innerException = jmsex.getLinkedException(); 
     if (innerException != null) { 
      logger.error("WebSphereMQMessageSender.processJMSException: Inner exception(s):"); 
     } 
     while (innerException != null) { 
      logger.error(innerException); 
      innerException = innerException.getCause(); 
     } 
    } 


    /** 
    * Release resources 
    * */ 
    private void cleanUp() { 
     if (producer != null) { 
      try { 
       producer.close(); 
      } catch (JMSException jmsex) { 
       logger.error("WebSphereMQMessageSender. cleanUp: Producer could not be closed."); 
       recordFailure(jmsex); 
      } 
     } 
     if (session != null) { 
      try { 
       session.close(); 
      } catch (JMSException jmsex) { 
       logger.error("WebSphereMQMessageSender. cleanUp: Session could not be closed."); 
       recordFailure(jmsex); 
      } 
     } 
     if (connection != null) { 
      try { 
       connection.close(); 
      } catch (JMSException jmsex) { 
       logger.error("WebSphereMQMessageSender. cleanUp: Connection could not be closed."); 
       recordFailure(jmsex); 
      } 
     } 
    } 
}