- 浏览: 733906 次
- 性别:
- 来自: 天津
-
文章分类
- 全部博客 (442)
- 中间件 (20)
- hibernate (13)
- spring (20)
- 数据库 (78)
- struts (8)
- ibatis (4)
- 前端 (61)
- linux,windows (21)
- it大环境 (32)
- IDE工具 (36)
- 感悟 (6)
- java基础 (40)
- 经典面试题 (10)
- exception总结 (14)
- 软件设计 (8)
- 工具类应用及新技术 (48)
- php (2)
- 微信 (1)
- 设计模式 (2)
- 重构 (3)
- 管理 (2)
- 工作笔记 (1)
- jmx (1)
- 算法 (4)
- 多线程同步 (2)
- 代码管理工具 (5)
- 代码检测及测试 (2)
- 缓存服务 (1)
- SOA及ROA (5)
- groovy (1)
- 网络编程 (2)
- 大数据 (6)
最新评论
-
love398146779:
我当然不能全写上面了,这只是其中一部分https连接。
java 建立 https连接 -
yuenkin:
大哥,这是双向认证吗?
java 建立 https连接 -
issu:
例如以下代码能遍历字符串"Tom:M ...
<c:forTokens>标签delims截取字符 -
love398146779:
2*3*5=30,是30个以上的请求才拒绝呀。
tomcat的maxThreads、acceptCount(最大线程数、最大排队数) -
love398146779:
2台跟1台一样的效果。
zookeeper与activemq最新存储replicatedLevelDB整合
最近做一个项目其中要用到websphere MQ 做数据传输。
以下是我整理用到的主要代码,以备后用。
package devx.articles.mqjms;
/**
* @author Ace Sun
* @version 创建时间:2011-4-3
* 类说明
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
public class MessageByMQ{
//定义队列管理器和队列的名称
private static String qmName;
private static String qName;
private static MQQueueManager qMgr;
static{
//设置环境:
//MQEnvironment中包含控制MQQueueManager对象中的环境的构成的静态变量,MQEnvironment的值的设定会在MQQueueManager的构造函数加载的时候起作用,
//因此必须在建立MQQueueManager对象之前设定MQEnvironment中的值.
MQEnvironment.hostname="58.2.217.60"; //MQ服务器的IP地址72
MQEnvironment.channel= "CLIENT.QM_ORANGE"; //服务器连接的通道 reciver
MQEnvironment.CCSID=1381; //服务器MQ服务使用的编码1381代表GBK、1208代表UTF(Coded Character Set Identifier:CCSID)
MQEnvironment.port=1415; //MQ端口 send QM port
qmName = "sendQM"; //MQ的队列管理器名称 sendQM QM_ORANGE
qName = "QM_APPLE"; //MQ远程队列的名称 Q1 QM_APPLE
try {
//定义并初始化队列管理器对象并连接
//MQQueueManager可以被多线程共享,但是从MQ获取信息的时候是同步的,任何时候只有一个线程可以和MQ通信。
qMgr = new MQQueueManager(qmName);
} catch (MQException e) {
// TODO Auto-generated catch block
System.out.println("初使化MQ出错");
e.printStackTrace();
}
}
/**
* 往MQ发送消息
* @param message
* @return
*/
public static int sendMessage(String message){
int result=0;
try{
//设置将要连接的队列属性
// Note. The MQC interface defines all the constants used by the WebSphere MQ Java programming interface
//(except for completion code constants and error code constants).
//MQOO_INPUT_AS_Q_DEF:Open the queue to get messages using the queue-defined default.
//MQOO_OUTPUT:Open the queue to put messages.
/*目标为远程队列,所有这里不可以用MQOO_INPUT_AS_Q_DEF属性*/
//int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
/*以下选项可适合远程队列与本地队列*/
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
//连接队列
//MQQueue provides inquire, set, put and get operations for WebSphere MQ queues.
//The inquire and set capabilities are inherited from MQManagedObject.
/*关闭了就重新打开*/
if(qMgr==null || !qMgr.isConnected()){
qMgr = new MQQueueManager(qmName);
}
MQQueue queue = qMgr.accessQueue(qName, openOptions);
//定义一个简单的消息
MQMessage putMessage = new MQMessage();
//将数据放入消息缓冲区
putMessage.writeUTF(message);
//设置写入消息的属性(默认属性)
MQPutMessageOptions pmo = new MQPutMessageOptions();
//将消息写入队列
queue.put(putMessage,pmo);
queue.close();
}catch (MQException ex) {
System.out.println("A WebSphere MQ error occurred : Completion code "
+ ex.completionCode + " Reason code " + ex.reasonCode);
ex.printStackTrace();
}catch (IOException ex) {
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
qMgr.disconnect();
} catch (MQException e) {
e.printStackTrace();
}
}
return result;
}
/**
* 从队列中去获取消息,如果队列中没有消息,就会发生异常,不过没有关系,有TRY...CATCH,如果是第三方程序调用方法,如果无返回则说明无消息
* 第三方可以将该方法放于一个无限循环的while(true){...}之中,不需要设置等待,因为在该方法内部在没有消息的时候会自动等待。
* @return
*/
/**
* @return
*/
/**
* @return
*/
public static String getMessage(String fileName){
String message=null;
try{
//设置将要连接的队列属性
// Note. The MQC interface defines all the constants used by the WebSphere MQ Java programming interface
//(except for completion code constants and error code constants).
//MQOO_INPUT_AS_Q_DEF:Open the queue to get messages using the queue-defined default.
//MQOO_OUTPUT:Open the queue to put messages.
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQMessage retrieve = new MQMessage();
//设置取出消息的属性(默认属性)
//Set the put message options.(设置放置消息选项)
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT;//Get messages under sync point control(在同步点控制下获取消息)
gmo.options = gmo.options + MQC.MQGMO_WAIT; // Wait if no messages on the Queue(如果在队列上没有消息则等待)
gmo.options = gmo.options + MQC.MQGMO_FAIL_IF_QUIESCING;// Fail if Qeue Manager Quiescing(如果队列管理器停顿则失败)
gmo.waitInterval = 1000 ; // Sets the time limit for the wait.(设置等待的毫秒时间限制)
/*关闭了就重新打开*/
if(qMgr==null || !qMgr.isConnected()){
qMgr = new MQQueueManager(qmName);
}
MQQueue queue = qMgr.accessQueue(qName, openOptions);
// 从队列中取出消息
queue.get(retrieve, gmo);
//message = retrieve.readUTF();
String message2 = retrieve.readUTF();
//System.out.println("===ss===="+message2.byteValue());
//message = retrieve.readLine();
System.out.println("The message is: " + message2);
/** 如果服务器上的文件是以BASE64Encoder编码形式创建的,则使用此段代码读取。
BASE64Decoder decoder = new BASE64Decoder();// 建立解码类实例
byte[] contentArray = decoder.decodeBuffer(message2);//解码生成byte数组
String path = "E://receivedMqXML//" + fileName;
FileOutputStream out = new FileOutputStream(new File(path));//调动输出流把文件写到指定的位置
out.write(contentArray, 0, contentArray.length);
out.close();
*/
String path = "E://receivedMqXML//" + fileName;
FileOutputStream out = new FileOutputStream(new File(path));//调动输出流把文件写到指定的位置
out.write(message2.getBytes());
out.close();
queue.close();
}catch (MQException ex) {
if(ex.completionCode==2&&ex.reasonCode==2033){
System.out.println("There are no record from MQ server");
}else{
System.out.println("A WebSphere MQ error occurred : Completion code "
+ ex.completionCode + " Reason code " + ex.reasonCode);
}
}catch (IOException ex) {
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
qMgr.disconnect();
} catch (MQException e) {
e.printStackTrace();
}
}
return message;
}
public static void main(String args[]) throws IOException {
/*下面两个方法可同时使用,也可以单独使用*/
StringBuffer sb = new StringBuffer();
String fileName = "offer_example.xml";//MyEmployee.xml
/**BASE64Encoder编码形式传送
InputStream in = new FileInputStream("E://sentXML//" + fileName); // 输入流读取要发送的文件
BASE64Encoder encoder = new BASE64Encoder();// 创建BASE64Encoder编码实例
byte[] data = new byte[in.available()];
in.read(data);
String stringFile = encoder.encode(data);
sb.append(stringFile);
sendMessage(sb.toString());
*/
/**以下为String方式传送*/
InputStream in = new FileInputStream("E://sentXML//" + fileName); // 输入流读取要发送的文件
String line;
String stringFile = "";
if(in != null) {
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("/n");
}
}finally {
in.close();
}
stringFile = sb.toString();
} else {
stringFile = "";
}
//sendMessage(stringFile);
getMessage(fileName);
}
}
以下是我整理用到的主要代码,以备后用。
package devx.articles.mqjms;
/**
* @author Ace Sun
* @version 创建时间:2011-4-3
* 类说明
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
public class MessageByMQ{
//定义队列管理器和队列的名称
private static String qmName;
private static String qName;
private static MQQueueManager qMgr;
static{
//设置环境:
//MQEnvironment中包含控制MQQueueManager对象中的环境的构成的静态变量,MQEnvironment的值的设定会在MQQueueManager的构造函数加载的时候起作用,
//因此必须在建立MQQueueManager对象之前设定MQEnvironment中的值.
MQEnvironment.hostname="58.2.217.60"; //MQ服务器的IP地址72
MQEnvironment.channel= "CLIENT.QM_ORANGE"; //服务器连接的通道 reciver
MQEnvironment.CCSID=1381; //服务器MQ服务使用的编码1381代表GBK、1208代表UTF(Coded Character Set Identifier:CCSID)
MQEnvironment.port=1415; //MQ端口 send QM port
qmName = "sendQM"; //MQ的队列管理器名称 sendQM QM_ORANGE
qName = "QM_APPLE"; //MQ远程队列的名称 Q1 QM_APPLE
try {
//定义并初始化队列管理器对象并连接
//MQQueueManager可以被多线程共享,但是从MQ获取信息的时候是同步的,任何时候只有一个线程可以和MQ通信。
qMgr = new MQQueueManager(qmName);
} catch (MQException e) {
// TODO Auto-generated catch block
System.out.println("初使化MQ出错");
e.printStackTrace();
}
}
/**
* 往MQ发送消息
* @param message
* @return
*/
public static int sendMessage(String message){
int result=0;
try{
//设置将要连接的队列属性
// Note. The MQC interface defines all the constants used by the WebSphere MQ Java programming interface
//(except for completion code constants and error code constants).
//MQOO_INPUT_AS_Q_DEF:Open the queue to get messages using the queue-defined default.
//MQOO_OUTPUT:Open the queue to put messages.
/*目标为远程队列,所有这里不可以用MQOO_INPUT_AS_Q_DEF属性*/
//int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
/*以下选项可适合远程队列与本地队列*/
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
//连接队列
//MQQueue provides inquire, set, put and get operations for WebSphere MQ queues.
//The inquire and set capabilities are inherited from MQManagedObject.
/*关闭了就重新打开*/
if(qMgr==null || !qMgr.isConnected()){
qMgr = new MQQueueManager(qmName);
}
MQQueue queue = qMgr.accessQueue(qName, openOptions);
//定义一个简单的消息
MQMessage putMessage = new MQMessage();
//将数据放入消息缓冲区
putMessage.writeUTF(message);
//设置写入消息的属性(默认属性)
MQPutMessageOptions pmo = new MQPutMessageOptions();
//将消息写入队列
queue.put(putMessage,pmo);
queue.close();
}catch (MQException ex) {
System.out.println("A WebSphere MQ error occurred : Completion code "
+ ex.completionCode + " Reason code " + ex.reasonCode);
ex.printStackTrace();
}catch (IOException ex) {
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
qMgr.disconnect();
} catch (MQException e) {
e.printStackTrace();
}
}
return result;
}
/**
* 从队列中去获取消息,如果队列中没有消息,就会发生异常,不过没有关系,有TRY...CATCH,如果是第三方程序调用方法,如果无返回则说明无消息
* 第三方可以将该方法放于一个无限循环的while(true){...}之中,不需要设置等待,因为在该方法内部在没有消息的时候会自动等待。
* @return
*/
/**
* @return
*/
/**
* @return
*/
public static String getMessage(String fileName){
String message=null;
try{
//设置将要连接的队列属性
// Note. The MQC interface defines all the constants used by the WebSphere MQ Java programming interface
//(except for completion code constants and error code constants).
//MQOO_INPUT_AS_Q_DEF:Open the queue to get messages using the queue-defined default.
//MQOO_OUTPUT:Open the queue to put messages.
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQMessage retrieve = new MQMessage();
//设置取出消息的属性(默认属性)
//Set the put message options.(设置放置消息选项)
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT;//Get messages under sync point control(在同步点控制下获取消息)
gmo.options = gmo.options + MQC.MQGMO_WAIT; // Wait if no messages on the Queue(如果在队列上没有消息则等待)
gmo.options = gmo.options + MQC.MQGMO_FAIL_IF_QUIESCING;// Fail if Qeue Manager Quiescing(如果队列管理器停顿则失败)
gmo.waitInterval = 1000 ; // Sets the time limit for the wait.(设置等待的毫秒时间限制)
/*关闭了就重新打开*/
if(qMgr==null || !qMgr.isConnected()){
qMgr = new MQQueueManager(qmName);
}
MQQueue queue = qMgr.accessQueue(qName, openOptions);
// 从队列中取出消息
queue.get(retrieve, gmo);
//message = retrieve.readUTF();
String message2 = retrieve.readUTF();
//System.out.println("===ss===="+message2.byteValue());
//message = retrieve.readLine();
System.out.println("The message is: " + message2);
/** 如果服务器上的文件是以BASE64Encoder编码形式创建的,则使用此段代码读取。
BASE64Decoder decoder = new BASE64Decoder();// 建立解码类实例
byte[] contentArray = decoder.decodeBuffer(message2);//解码生成byte数组
String path = "E://receivedMqXML//" + fileName;
FileOutputStream out = new FileOutputStream(new File(path));//调动输出流把文件写到指定的位置
out.write(contentArray, 0, contentArray.length);
out.close();
*/
String path = "E://receivedMqXML//" + fileName;
FileOutputStream out = new FileOutputStream(new File(path));//调动输出流把文件写到指定的位置
out.write(message2.getBytes());
out.close();
queue.close();
}catch (MQException ex) {
if(ex.completionCode==2&&ex.reasonCode==2033){
System.out.println("There are no record from MQ server");
}else{
System.out.println("A WebSphere MQ error occurred : Completion code "
+ ex.completionCode + " Reason code " + ex.reasonCode);
}
}catch (IOException ex) {
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
qMgr.disconnect();
} catch (MQException e) {
e.printStackTrace();
}
}
return message;
}
public static void main(String args[]) throws IOException {
/*下面两个方法可同时使用,也可以单独使用*/
StringBuffer sb = new StringBuffer();
String fileName = "offer_example.xml";//MyEmployee.xml
/**BASE64Encoder编码形式传送
InputStream in = new FileInputStream("E://sentXML//" + fileName); // 输入流读取要发送的文件
BASE64Encoder encoder = new BASE64Encoder();// 创建BASE64Encoder编码实例
byte[] data = new byte[in.available()];
in.read(data);
String stringFile = encoder.encode(data);
sb.append(stringFile);
sendMessage(sb.toString());
*/
/**以下为String方式传送*/
InputStream in = new FileInputStream("E://sentXML//" + fileName); // 输入流读取要发送的文件
String line;
String stringFile = "";
if(in != null) {
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("/n");
}
}finally {
in.close();
}
stringFile = sb.toString();
} else {
stringFile = "";
}
//sendMessage(stringFile);
getMessage(fileName);
}
}
发表评论
-
HttpUrlConnection与httpclient的速度
2015-03-10 17:59 903文件越大,可能HttpUrlConnection的速度优势越明 ... -
FastDFS与hadoop的HDFS区别
2015-01-12 16:12 4242主要是定位和应用场合不一样。 hadoop的文件系统HDFS主 ... -
RequestDispatcher实现文件下载
2015-01-04 14:55 783本来我使用的是文件流下载的方式,在Tomcat下可行,但是在W ... -
javax.mail.MessagingException: 501 5.0.0 HELO requires domain address
2014-12-22 17:32 7http://zouhuajian01.blog.163.co ... -
javax.mail.MessagingException: 501 5.0.0 HELO requires domain address
2014-12-22 17:32 1088http://zouhuajian01.blog.163.co ... -
https协议网页能够被搜索引擎收录吗?
2014-11-12 17:07 581百度现在只能收录少部分的https,大部分的https网页无法 ... -
aes加解密
2014-10-29 13:18 772import java.io.File; import ja ... -
udp测试
2014-10-22 15:39 522udp,常用于聊天室,直接向服务发送信息,不进行3次握手。 服 ... -
aio测试
2014-10-22 14:22 718由操作系统来做异步 服务端: package aio; ... -
fastdfs使用实战(Java实例篇)
2014-09-29 18:11 22568一、创建一个maven的webproject,叫file-ma ... -
谷歌(Chrome)安装Advanced REST Client插件
2014-09-29 10:44 2745以前用过jmeter测试各种url连接,soapui测试web ... -
sftp工具类
2014-09-28 13:29 985import java.io.File; import ja ... -
quartz配置
2014-09-22 10:35 405以前做过好几个quartz的应用项目,但都没有记录,当再次用到 ... -
ftp工具类
2014-09-19 18:08 758每回用到总去网上找一通,还是自已总结下比较好 package ... -
使用 JCaptcha 开发图形和声音验证码
2014-08-18 10:13 891http://www.ibm.com/developerwor ... -
Joda-Time 简介
2014-08-18 10:01 544iteye转的文章与自已的文章,不能放到一起。真麻烦。 转一个 ... -
log.isDebugEnabled()
2014-08-06 11:55 789在使用log4j,common-log这样的log框架时,发现 ... -
zookeeper与activemq最新存储replicatedLevelDB整合
2014-08-01 19:57 7048测试环境:三台VM虚拟机centos6.4 64位 mini版 ... -
一致性哈希算法原理 .
2014-08-01 19:53 581http://baike.baidu.com/view/158 ... -
map,xml互转
2014-06-24 11:46 96131.这个转出来会有很多空格package cn.paypalm ...
相关推荐
### IBM Websphere MQ 教程之备份与恢复 #### 实验目的 本教程旨在让学员深入了解IBM Websphere MQ中的消息生命周期管理及其备份恢复机制。通过一系列实践操作,学员能够掌握如何创建线性日志队列管理器、向本地...
在IT行业中,WebSphere MQ(原名MQSeries)是IBM提供的一款企业级的消息中间件产品。它允许应用程序之间通过异步消息传递进行通信,有效地解耦了系统之间的依赖,增强了系统的可扩展性和可靠性。本篇文章将深入探讨...
最后,"WebSphere MQ Integrator"是IBM的中间件产品,用于消息传递和数据交换,它确保了跨系统通信的可靠性和安全性。用户可以通过手册了解如何设置和管理消息队列,以及如何实现异步处理。 这些手册共同构建了一个...
该文档为 IBM 内部资料,对于希望深入了解并正确实施 WebSphere Portal、WebSphere Application Server 以及 WebSphere MQ 的用户来说具有极高的价值。 #### 目标 本篇的目标是为读者提供一个全面的视角,理解如何...
根据统计,WebSphere在工作市场上的需求稳定且不断增长,尤其是在WebSphere 6.1版本发布后,由于IBM将其许多软件如MQ Series和IBM Directory Server等集成到WebSphere,使得这个领域的工作机会更加丰富。然而,简历...
例如,WebSphere可能更倾向于IBM的MQ系列,而WebLogic则可能与Oracle数据库有更好的兼容性。 10. **社区支持**:虽然两者都有庞大的用户社区和专业论坛,如IBM开发者Works和Oracle社区,WebSphere可能由于IBM的长期...