package psdi.app.iface.mdm.mq;

import com.ibm.mq.*;
import java.io.IOException;
import java.util.Hashtable;

public class SendMqUtil {
   // private String host = "192.168.106.36";//测试环境
    private String host = "192.168.106.33";//生产环境
    private Integer port=1415;
    private String queueManager="PIP_IN";
    private String channel="SVRCONN_GW_IN";
    private String username;
    private String password;
    private long receiveTimeout=60000;
    private String qName="IBM.SERVICE.POSUPDATA.REQUESTER.IN";
    private Integer ccsid=1208;
    /**
     * 发送mq数据
     *
     * @param destinationName 目的地
     * @param message         消息
     * @throws
     */
    public void convertAndSend(String destinationName, String message) {
        System.out.println("message="+message);
        MQQueueManager qMgr;
        Hashtable properties = new Hashtable();
        try {
            properties.put("hostname", host);
            properties.put("port", port);
            properties.put("channel", channel);
            properties.put("CCSID", ccsid);
            // Create a connection to the queue manager
            qMgr = new MQQueueManager(queueManager, properties);
            // Set up the options on the queue we wish to open...
            int openOptions = 16;
            // Now specify the queue that we wish to open,
            // and the open options...
            MQQueue remoteQ = qMgr.accessQueue(qName, openOptions);
            // Define a simple WebSphere MQ message, and write some text in UTF format..
            MQMessage putMessage = new MQMessage();
            putMessage.writeString(message);
            System.out.println("putMessage"+putMessage.toString());
            // specify the message options...
            MQPutMessageOptions pmo = new MQPutMessageOptions();
            // accept the defaults, same as MQPMO_DEFAULT
            // put the message on the queue
            remoteQ.put(putMessage, pmo);
            // Close the queue...
            remoteQ.close();
            // Disconnect from the queue manager
            qMgr.disconnect();
        } catch (MQException ex) {
            System.out.println("MQException====================="+ex.toString());
        } catch (IOException ex) {
            System.out.println("IOException====================="+ex.toString());
        } catch (Exception ex) {
            System.out.println("Exception===================="+ex.toString());
        }
    }
}
