java工作流和mq相结合可以采用以下3种方式:
创新互联公司是一家专业从事成都网站设计、成都网站制作的网络公司。作为专业网站建设公司,创新互联公司依托的技术实力、以及多年的网站运营经验,为您提供专业的成都网站建设、成都全网营销及网站设计开发服务!
1、在工作流中使用消息队列:可以使用消息队列作为工作流中的任务处理引擎,将任务分配到消息队列中,并通过消息队列中的消息通知任务执行状态或结果。
2、在消息队列中使用工作流:可以使用工作流作为消息队列中的消息处理引擎,将消息作为工作流中的任务,通过工作流引擎执行任务,并根据任务执行结果发送消息通知。
3、工作流和消息队列相互协作:可以将工作流和消息队列结合起来,实现复杂的任务处理和协作场景,例如多个任务之间的依赖关系、任务执行的顺序控制、任务执行的并行处理等。
我用的方法是:
MQQueueManager qMgr = new MQQueueManager("BVMTEST");
System.out.println("queue manager is connected!");
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
/* 打开队列 */
com.ibm.mq.MQQueue queue = qMgr.accessQueue("test1", openOptions);
然后在调用queue.getCurrentDepth()的方法的时候居然报了异常:
MQJE001: 完成代码是 2,原因为 2038
如果我不在此处调用这个方法,而在后面进行
queue.put(outMsg, new MQPutMessageOptions());方法,居然可以成功放入测试信息.
给你一个有用的代码大全:
密码:exn4
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import com.fxun.plant.vo.CommandVO;
public class ProducerTool extends Thread {
private Destination destination;
// private int messageCount = 500;
long sleepTime = 0;
// private boolean verbose = true;
// private int messageSize = 255;
private long timeToLive = 0; // 消息存活时间
private String user = ActiveMQConnection.DEFAULT_USER;
private String password = ActiveMQConnection.DEFAULT_PASSWORD;
private String url = ActiveMQConnection.DEFAULT_BROKER_URL;
private String subject; // subject的名字,默认是TOOL.DEFAULT
// private boolean topic;
private boolean transacted = false; // 是否采用事务
// private boolean persistent = false;
private P2PQueue p2pQueue;
public ProducerTool(String user, String password, String url, String subject) {
this.user = user;
this.password = password;
this.url = url;
this.subject = subject;
}
public void run() {
Connection connection = null;
try {
// Create the connection.
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url);
connection = connectionFactory.createConnection();
connection.start();
// Create the session
Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(subject);
// Create the producer.
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.setTimeToLive(timeToLive);
CommandVO commandVO = null;
int size = 0;
while (true) {
size = p2pQueue.getSize();
if (size 0) {
BytesMessage message = session.createBytesMessage();
message.writeInt(size);
for (int i = 0; i size; i++) {
commandVO = p2pQueue.pool();
if(commandVO == null) {
message.writeInt(0);
} else {
message.writeInt(commandVO.getCountSize());
message.writeInt(commandVO.getCommand()); // 指令
message.writeBytes(commandVO.getContent()); // 内容
}
}
producer.send(message);
}
Thread.sleep(300);
}
// Use the ActiveMQConnection interface to dump the connection
// stats.
// ActiveMQConnection c = (ActiveMQConnection) connection;
// c.getConnectionStats().dump(new IndentPrinter());
} catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
} finally {
try {
connection.close();
} catch (Throwable ignore) {
}
}
}
public void setPassword(String pwd) {
this.password = pwd;
}
public void setSleepTime(long sleepTime) {
this.sleepTime = sleepTime;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setTimeToLive(long timeToLive) {
this.timeToLive = timeToLive;
}
public void setTransacted(boolean transacted) {
this.transacted = transacted;
}
public void setUrl(String url) {
this.url = url;
}
public void setUser(String user) {
this.user = user;
}
public P2PQueue getP2pQueue() {
return p2pQueue;
}
public void setP2pQueue(P2PQueue p2pQueue) {
this.p2pQueue = p2pQueue;
}
}
原代码都发给你