javamq代码 javamq怎么用

mq java 怎么判断队列为空MQException
该类包含WebSphere MQ 完成代码和错误代码常量的定义 。以MQCC_开始的常量是WebSphere MQ 完成代码,而以MQRC_开始的常量则是WebSphere MQ 原因代码 。只要出现WebSphere MQ
错误 , 就会给出MQException 。
MQGetMessageOptions
该类包含控制MQQueue.get()方法行为的选项 。
MQManagedObject
该类是MQQueueManager、MQQueue 和MQProcess 类的超类 。它提供查询并设置这些资源属性的能力 。
------解决方案--------------------
去取一次,得到 2033 错误就是没有消息符合你的条件 。
使用 PCF 查询队列资料:
/**
* @return current depth of queue connected currently.
* @throws Exception
*/
public QueueInfo queryQueueInfo() throws Exception {
if (!checkStatus2(this.queueManager)) {
throw new IllegalStateException("Not Connected to queue manager.");
}
PCFMessageAgent agent = null;
try {
agent = new PCFMessageAgent(this.queueManager);
// Inquiry Queue NameCurrent Depth.
int[] attrs = {
CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH,
CMQC.MQIA_OPEN_INPUT_COUNT, CMQC.MQIA_OPEN_OUTPUT_COUNT,
CMQC.MQIA_Q_TYPE, CMQC.MQIA_DEFINITION_TYPE, CMQC.MQIA_INHIBIT_GET,
CMQC.MQIA_INHIBIT_PUT };
PCFParameter[] parameters = {
new MQCFST(CMQC.MQCA_Q_NAME , getInputQueue().getText().trim()),
new MQCFIL(CMQCFC.MQIACF_Q_ATTRS , attrs) };
// logger.log("Querying current depth of current queue.");
MQMessage[] responses = agent.send(CMQCFC.MQCMD_INQUIRE_Q, parameters);
QueueInfo info = new QueueInfo();
for (int i = 0; iresponses.length; i) {
MQCFH cfh = new MQCFH(responses[i]);
// Check the PCF header (MQCFH) in the response message
if (cfh.reason == 0) {
String name = "";
Integer depth = new Integer(0);
for (int j = 0; jcfh.parameterCount; j) {// Extract what we want from the returned attributes
PCFParameter p = PCFParameter.nextParameter(responses[i]);
switch (p.getParameter()) {
case CMQC.MQCA_Q_NAME:
name = (String) p.getValue();
info.name = name;
break;
case CMQC.MQIA_CURRENT_Q_DEPTH:
depth = (Integer) p.getValue();
info.depth = depth.intValue();
break;
case CMQC.MQIA_OPEN_INPUT_COUNT:
Integer inputCount = (Integer) p.getValue();
info.inputCount = inputCount.intValue();
break;
case CMQC.MQIA_OPEN_OUTPUT_COUNT:
Integer outputCount = (Integer) p.getValue();
info.outputCount = outputCount.intValue();
break;
case CMQC.MQIA_Q_TYPE:
info.type = ((Integer) p.getValue()).intValue();
break;
case CMQC.MQIA_DEFINITION_TYPE:
【javamq代码 javamq怎么用】info.definitionType = ((Integer) p.getValue()).intValue();
break;
case CMQC.MQIA_INHIBIT_PUT:
info.putNotAllowed = ((Integer) p.getValue()).intValue() == 1;
break; case CMQC.MQIA_INHIBIT_GET:
info.getNotAllowed = ((Integer) p.getValue()).intValue() == 1;
default:
}
}
//System.out.println("Queue "name" curdepth "depth);
return info;
} else {
System.out.println("PCF error:\n"cfh);
// Walk through the returned parameters describing the error
for (int j = 0; jcfh.parameterCount; j) {
System.out.println(PCFParameter.nextParameter(responses[0]));
}
throw new Exception("PCF Error [reason :"cfh.reason"]");
}
}
return null;
} catch (Exception e) {
throw e;
} finally {
if (agent != null) {
try {
agent.disconnect();
} catch (Exception e) {
logger.log(e);
}
}
}
MQ java源代码谁有?IBM拿去卖钱的,不可能有源代码啊 。我这有一些乱七八糟的相关文档,给你发过去,你看一下吧,不知道对你有没有用 。
PS:都是英文的 , 我也没看过 。
我还有一些MB的文档,要就HI我 。
用java代码如何设置activemq消息持久化到数据库中?ActiveMQ持久化消息的二种方式;
1、持久化为文件
这个装ActiveMQ时默认就是这种,只要设置消息为持久化就可以了 。涉及到的配置和代码有:
persistenceAdapter
kahaDB directory="${activemq.base}/data/kahadb"/
/persistenceAdapter
producer.Send(request, MsgDeliveryMode.Persistent, level, TimeSpan.MinValue);
2、持久化为MySql
首先需要把MySql的驱动放到ActiveMQ的Lib目录下,我用的文件名字是:mysql-connector-java-5.0.4-bin.jar
接下来修改配置文件
persistenceAdapter
jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#derby-ds"/
/persistenceAdapter
在配置文件中的broker节点外增加
bean id="derby-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
property name="driverClassName" value="https://www.04ip.com/post/com.mysql.jdbc.Driver"/
property name="url" value="https://www.04ip.com/post/jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/
property name="username" value="https://www.04ip.com/post/activemq"/
property name="password" value="https://www.04ip.com/post/activemq"/
property name="maxActive" value="https://www.04ip.com/post/200"/
property name="poolPreparedStatements" value="https://www.04ip.com/post/true"/
/bean
从配置中可以看出数据库的名称是activemq,需要手动在MySql中增加这个库 。
然后重新启动消息队列,会发现多了3张表
1:activemq_acks
2:activemq_lock
3:activemq_msgs
java 怎么样调用IBM MQ 或者通信问题websphere mq: 用于传输信息 具有跨平台javamq代码的功能 。
1 安装websphere mq 并启动
2 websphere mq 建立 queue Manager (如javamq代码:MQSI_SAMPLE_QM)
3 建立queue 类型选择 Local类型 的 (如lq)
3 建立channels 类型选择Server Connection (如BridgeChannel)
java 代码如下javamq代码:
package test.mq;
import com.ibm.mq.*;
/*
* 成功的访问mq 的java 类
*/
public class FirstMqTest {
//public static void main(String[] args[]){
//FirstMqTest first = new FirstMqTest();
//first.test();
//}
public static void main(String args[]){
FirstMqTest first = new FirstMqTest();
first.test();
}
public void test(){
String qManager = "MQSI_SAMPLE_QM"; //QueueManager name
String qName = "lq";//Queue Name
try {
//configure connection parameters
MQEnvironment.hostname="172.16.17.123";//MQ Server name or IP
//MQEnvironment.port=1414;//listenr port
MQEnvironment.channel="BridgeChannel";//Server-Connection Channel
MQEnvironment.CCSID =1381;
// Create a connection to the QueueManager
System.out.println("Connecting to queue manager: " qManager);
MQQueueManager qMgr = new MQQueueManager(qManager);
// Set up the options on the queue we wish to open
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we wish to open and the open options
System.out.println("Accessing queue: " qName);
MQQueue queue = qMgr.accessQueue(qName, openOptions);
// Define a simple WebSphere MQ Message ...
MQMessage msg = new MQMessage();
// ... and write some text in UTF8 format
msg.writeUTF("Hello, World!");
// Specify the default put message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
// Put the message to the queue
System.out.println("Sending a message...");
/*
* 在此测试一下 mq 的传输次列
*
*/
for(int j=0;j 5;j){
String str ="test11111111111";
str = str j;
msg.writeUTF(str);
queue.put(msg, pmo);
}
queue.put(msg, pmo);
// Now get the message back again. First define a WebSphere MQ message
// to receive the data
MQMessage rcvMessage = new MQMessage();
// Specify default get message options
MQGetMessageOptions gmo = new MQGetMessageOptions();
// Get the message off the queue.
System.out.println("...and getting the message back again");
queue.get(rcvMessage, gmo);
// And display the message text...
String msgText = rcvMessage.readUTF();
System.out.println("The message is: "msgText);
// Close the queue
System.out.println("Closing the queue");
queue.close();
// Disconnect from the QueueManager
System.out.println("Disconnecting from the Queue Manager");
qMgr.disconnect();
System.out.println("Done!");
}
catch (MQException ex) {
System.out.println("A WebSphere MQ Error occured : Completion Code "
ex.completionCode" Reason Code "ex.reasonCode);
}
catch (java.io.IOException ex) {
System.out.println("An IOException occured whilst writing to the message buffer: "
ex);
}
}
}
javamq代码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容 , 更多关于javamq怎么用、javamq代码的信息别忘了在本站进行查找喔 。

    推荐阅读