求助:关于jms的持久性,和消息选择的问题
希望有那位大哥给于解决.
所有的代码如下:
try
{
ctx = new InitialContext();
topicFactory = (TopicConnectionFactory)ctx.lookup("autopracticeConnectionFactory");
tcon = topicFactory.createTopicConnection();
topicSession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)ctx.lookup("autopracticetopic");
TopicPublisher publisher= topicSession.createPublisher(topic);
msg = topicSession.createTextMessage();
tcon.start();
msg.setStringProperty("char",ss);
msg.setText(strTopicInfo);
publisher.publish(msg); //发送消息到topic
_logger.debug("the message send ok.the message value is " + strTopicInfo);
publisher.close();
topicSession.close();
tcon.close();
}
catch(NamingException e)
{
_logger.debug("the throw nameingexception.");
}
catch(JMSException e)
{
_logger.debug("the throw jmsexception.");
}
}
第一个参数是消息的内容,第二个是传入的时间转化成的字符串作为消息比较的property.消息是能发送成功的,参数传的也是正确的.
try {
if(incomingMsg instanceof TextMessage)
{
msgText = (TextMessage)incomingMsg;
String msgtype = msgText.getStringProperty("char");
String year = msgtype.substring(0,4);
_logger.debug("the str year is " + year);
String month = msgtype.substring(4,6);
_logger.debug("the str month is" + month);
String day = msgtype.substring(6,8);
_logger.debug("the str day is " + day);
GregorianCalendar curCalendar = new GregorianCalendar();
Date curDate = (Date) curCalendar.getTime();
DateConvert dateConvert = new DateConvert(curDate);
String nyear = dateConvert.getYear();
String nmonth = dateConvert.getMonth();
if(nmonth.length()==1)nmonth="0"+nmonth;
String nday = dateConvert.getDay();
if(nday.length()==1)nday="0"+nday;
_logger.debug("the year is " + nyear);
_logger.debug("the month is " + nmonth);
_logger.debug("the day is "+ nday);
if(day.equals(nday))
{
msgtime = msgText.getText();
_logger.debug("MMMMMMMMMMM MMMMMMMMMM get the message ok value is "+msgtime);
System.out.println("get the message ok value is"+msgtime);
}
else
{
_logger.debug("it is not.");
}
}
} catch (JMSException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
} catch (Throwable te){
te.printStackTrace();
}
}
简单的做了一下比较,就是当传入的时间字符串和系统时间字符串相同的时候,就会执行,这也是可以的但是每次都会把topic中的所有消息都执行了
ejb-jar 的代码如下:
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
weblogic-ejb-jar 代码如下:
'-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN'
'http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd'>
webloigc的config.xml的关于jms的配置如下:
这是整个bean的代码,我想解决的问题就是
1:发送到topic中的消息,如果我不手动删除是不会删除的,也就是说系统不会自动的把我发送的消息给over掉,或者说我用过的消息删除,还没有处理的消息留在topic中
2:我怎样可以用消息选择机制,自动过虑我的消息让到时间的才去执行
3:即时我的webloigc 死掉了,没有执行的消息在webloigc启动后仍然能够继续执行
希望各位前辈帮帮小弟,尽快解决一下问题
小弟在此先谢过.
If you want to use MDB, one solution is to use the Time to Deliver feature in weblogic MDB to schedule a message that will be consumed exactly after the re-activate date is passed.
But the simple soultion would be change your database and add the life cycle fields for your records.
J2EE 1.4 Timer可以有定时功能,查询一下可以知道,但是容器不一定支持1.4标准。
To use message selector, please be carefule about the seetings on message redelivery, since you might want the producer to re-send message every day so that the consumer can do the selection every day. Another thing is message selectin criteria should only exists in the message header.
DB soultion is more or less the most common one to use. In your table, for example COMPANY_TAXABLE, add a date field such as EFFECTIVE_FROM. Append this criteria in your SQL to filter out non effective companies.
Are you from 郑州? Me too... Nice to meet you here.
剩下两种方式都不错,用message-selector配置上要注意,redelivery的时间间隔和重发次数
to xok:
acknowledge mode 不需要特别设置吗,这个我不太确定了