JAVA MQ编码部分
来源:互联网 发布:电力网络摄像头 编辑:程序博客网 时间:2024/05/17 09:30
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.ibm.mq.MQException;
import com.ibm.mq.MQQueueManager;
/**
* @author HP
*
*/
public class MQCommon {
public static String MQ_MANAGER = null; //队列管理器名称
public static MQQueueManager qMgr = null;
public static Properties props = null;
public static MQQueueManager getMQQueueManager() {
if(qMgr==null) {
try {
qMgr = new MQQueueManager(MQ_MANAGER);
} catch (MQException e) {
e.printStackTrace();
}
}
return qMgr;
}
public static Properties getProperties() {
if(props==null) {
try {
props = new Properties();
InputStream ips = new BufferedInputStream(new FileInputStream("D://MQ.properties"));
props.load(ips);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return props;
}
public static void mqClose() {
try {
if(qMgr!=null) {
qMgr.close();
qMgr.disconnect();
qMgr = null;
}
} catch (MQException e) {
e.printStackTrace();
}
}
}
package com.founder.gome.bg.service.mq;
import com.founder.gome.bg.service.mq.impl.POServiceImpl;
import com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
public class MQReceiver implements Runnable {
private String MQ_QUEUE_NAME = "QL_GOME02_EC_SO_TO_DRAGON_SO";
private MQQueueManager qMgr = MQCommon.getMQQueueManager();
public MQReceiver (String mqQueueName) {
if (null != mqQueueName && !"".equals(mqQueueName)) {
this.MQ_QUEUE_NAME = mqQueueName;
}
}
@SuppressWarnings("unchecked")
public void run() {
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE;
MQQueue queue = null;
try {
MQEnvironment.hostname = MQCommon.props.getProperty("MQ_HOST_NAME");
MQEnvironment.channel = MQCommon.props.getProperty("MQ_CHANNEL");
MQEnvironment.port = Integer.valueOf(MQCommon.props.getProperty("MQ_PROT"));
MQEnvironment.CCSID = Integer.valueOf(MQCommon.props.getProperty("MQ_CCSID"));
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
queue = qMgr.accessQueue(MQ_QUEUE_NAME, openOptions, null, null,null);
int depth = queue.getCurrentDepth();
while(depth-- > 0)
{
MQMessage msg = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
queue.get(msg, gmo);
int index = msg.getMessageLength();
byte[] buffer = new byte[index];
msg.readFully(buffer, 0, index);
String message = new String(buffer, "utf-8");
new POServiceImpl().getXML(message, MQ_QUEUE_NAME);
}
} catch (MQException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(queue!=null){
try {
queue.close();
} catch (MQException e) {
e.printStackTrace();
}
}
}
}
}
package com.founder.gome.bg.service.mq;
import java.io.IOException;
import com.founder.gome.bg.service.mq.impl.POServiceImpl;
import com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
public class MQSender implements Runnable {
private String MQ_QUEUE_NAME = "QR_GOME02_EC_SO_TO_DRAGON_SO";
private String xml;
private MQQueue mqQueue = null;
public MQSender(String xml, String mqQueueName) {
this.xml = xml;
if (null != mqQueueName && !"".equals(mqQueueName)) {
this.MQ_QUEUE_NAME = mqQueueName;
}
}
@SuppressWarnings("unchecked")
public void run() {
try {
MQEnvironment.hostname = MQCommon.props.getProperty("MQ_HOST_NAME");
MQEnvironment.channel = MQCommon.props.getProperty("MQ_CHANNEL");
MQEnvironment.port = Integer.valueOf(MQCommon.props.getProperty("MQ_PROT"));
MQEnvironment.CCSID = Integer.valueOf(MQCommon.props.getProperty("MQ_CCSID"));
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
int sendOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
mqQueue = MQCommon.getMQQueueManager().accessQueue(MQ_QUEUE_NAME, sendOptions, null, null, null);
MQPutMessageOptions mqPutMessageOptions = new MQPutMessageOptions();
MQMessage mqMessage = new MQMessage();
mqMessage.write(xml.getBytes("utf-8"));
mqQueue.put(mqMessage, mqPutMessageOptions);
POServiceImpl poServiceImpl = new POServiceImpl();
poServiceImpl.writeFile(xml);
} catch (MQException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (mqQueue != null) {
try {
mqQueue.close();
} catch (MQException e) {
e.printStackTrace();
}
}
}
}
}
- JAVA MQ编码部分
- Java编码规范(部分)
- MQ 中编码问题
- Android编码规范(Java部分)
- Java Spring 编码总结(部分)
- MQ java 基础编程
- MQ java Code
- java连接ibm mq
- Java调用MQ队列
- java连接ibm mq
- Java 连接MQ
- JAVA 调用MQ
- Java调用MQ队列
- Java连接IBM MQ
- JAVA连接IBM MQ
- Java 连接active mq
- Java中使用MQ
- 修改mq的编码字符集标识
- 两列布局——左侧宽度固定,右侧宽度自适应的两种方法
- user_tab_columns和user_col_comments区别
- js页面宽度获取
- Caliburn Micro Part 4: The Event Aggregator
- 欢迎使用CSDN-markdown编辑器
- JAVA MQ编码部分
- IES Light Profiles
- Linux软连接和硬链接
- Spring Security + Hibernate XML Example
- js 毫秒 转date
- hessian spring 调用
- Caliburn Micro Part 5: The Window Manager
- [LeedCode OJ]#231 Power of Two
- Android 打包签名(一)