发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 大数据 扩展性 并发编程 事件驱动 分布式 SOA

关于Jms

2003-10-09 13:55
赞助商链接

weblogic.jms.common.InvalidClientIDException: Client id, BibleJMSClient, is in use

BibleJMSClient 是我定义的client id

运行AsyncQueueReceiver 进行接受可以收到,队列中的消息


但是不关闭AsyncQueueReceiver 运行发送程序 BibleQueueSender 出现上面的错误








package bible.jms;

import javax.jms.*;
import javax.naming.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/


public class BibleQueueSender {
public BibleQueueSender() {
}

public static void main(String args[]) {
Context ctx= null;
Hashtable ht= new Hashtable();
QueueConnectionFactory qfactory=null;
QueueConnection qconn =null;
QueueSession qsession=null;
QueueSender qsender=null;
Queue q=null;
TextMessage textMsg=null;
String msg;
try {
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://localhost:7001");
ctx=new InitialContext(ht);
qfactory=(QueueConnectionFactory)ctx.lookup(
"BibleJMSFactory");
qconn =qfactory.createQueueConnection();
qsession=qconn.createQueueSession(false,javax.jms.QueueSession.AUTO_ACKNOWLEDGE);
q=(Queue) ctx.lookup(
"BibleJMSQueue");

qsender=qsession.createSender(q);
System.out.println(
"dddddddd...");
textMsg=qsession.createTextMessage();

for (int i=0;i<100;i++) {
msg=
"Message # " + i;
textMsg.clearBody();
textMsg.setIntProperty(
"serverity",i);
textMsg.setText(msg);
//System.out.println("Sending Message: "+ msg);
qsender.send(textMsg);
}

//textMsg.setText("stop");
//qsender.send(textMsg);
System.out.println(
"finished...");

}catch (Exception e){
e.printStackTrace();
}
finally {
try {
qsender.close();
qsession.close();
qconn.close();
}catch (Exception e){
e.printStackTrace();
}
}
}

}






package bible.jms;

import javax.jms.*;
import javax.naming.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/


public class AsyncQueueReceiver implements MessageListener {

private boolean finished =false;
private Context ctx= null;
private Hashtable ht= new Hashtable();
private QueueConnectionFactory qfactory=null;
private QueueConnection qconn =null;
private QueueSession qsession=null;
private QueueReceiver qreceiver=null;
private Queue q=null;


public void init() {
try {
ht= new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://localhost:7001");
ctx=new InitialContext(ht);
qfactory=(QueueConnectionFactory)ctx.lookup(
"BibleJMSFactory");
qconn =qfactory.createQueueConnection();
qsession=qconn.createQueueSession(false,javax.jms.QueueSession.AUTO_ACKNOWLEDGE);
q=(Queue) ctx.lookup(
"BibleJMSQueue");

qreceiver= qsession.createReceiver(q);
qreceiver.setMessageListener(this);
qconn.start();
} catch (Exception e){
e.printStackTrace();
}
}


public void close() throws JMSException
{
try {
qreceiver.close();
qsession.close();
qconn.close();
}catch (Exception e){
e.printStackTrace();
}

}


public AsyncQueueReceiver() {
}
public void onMessage(Message message) {
if (message instanceof TextMessage){
try {
TextMessage textMessage=(TextMessage)message;
String msg= textMessage.getText();
System.out.println(
"Received Message :"+ msg);


if (msg.equals(
"stop")) {
synchronized (this) {
finished=true;
this.notifyAll();
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
}

public static void main(String args[]) {
try {
AsyncQueueReceiver qr= new AsyncQueueReceiver();
qr.init();
System.out.println(
"aaaaaaaaa...");

synchronized (qr) {
while(!qr.finished) {
try {
qr.wait();
}
catch (InterruptedException ie){}
}
qr.close();
}
}catch (Exception e){
e.printStackTrace();
}
}
}

1
2003-10-11 03:37

clientid 只是针对订阅/发布方式的,在一般队列方式不可用.
在weblogic中将队列设置中的clientid 去掉即可.

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com