• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Message seems disappear???

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks, it is so urgent for me to solve this problem. It is haunting me over 3 days. It does look strange. Following is the problem.

Before I go ahead with the problem, I describe my ENV first.
JBOSS3.2.3, J2SDK1.4.2.

1> JMS Publisher (Session Bean) publishes TextMessage to topic (topic/testTopic). From JMX-Console, the bean has been activated and message has been send out.

2> JMS Receiver (Message Driven Bean) listening on topic (topic/testTopic). From JMX-Console, topic/testTopic does have this nonDurable subscription.

3> A Client is used to drive Session Bean succesfully executed.

4> Bothe Session Bean and MDB have been 100% sucessfully deployed in JBOSS.

5> Here are the codes:


Client:

ublic class Client{

Context ctx = null;

public Client() {
setupContext();
sendJMS();
}

public static void main(String[] args){
new Client();
}

private void setupContext(){

try {

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "192.168.1.11");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");

ctx = new InitialContext(env);
}
catch(Exception e){
e.printStackTrace();
}

}

private void sendJMS(){
try{

if(System.getSecurityManager() == null){
System.setSecurityManager(new RMISecurityManager());
}


Object obj = ctx.lookup("dat/JMSPublisher");

//Class[] c = obj.getClass().getInterfaces();
//System.out.println(obj.getClass().getSuperclass().getName());
//for (int i=0; i<c.length; i++) {
// System.out.println(c[i].getName());
//}

PublisherHome home = (PublisherHome)
PortableRemoteObject.narrow(obj, PublisherHome.class);


PublisherRemote publisher = home.create();

publisher.publishMessages();
publisher.remove();
}
catch(Exception e){
e.printStackTrace();
}


}


}

Lookup Session Bean and call the method.


JMS Publisher (Session Bean):

public class JMSPublisherEJB implements SessionBean {

SessionContext sc = null;
TopicConnection conn = null;
Topic topic = null;

final static String messageTypes[] = {"Nation/World",
"Metro/Region", "Business", "Sports", "Living/Arts",
"Opinion"};

static final Logger logger = Logger.getLogger("netsure.capman.adapterEngine.Publisher.JMSPublisherEJB");


public JMSPublisherEJB() {

addLogger();

logger.info("In PublisherBean() (constructor)");
}

private void addLogger(){
try{
FileHandler handler = new FileHandler("//home/netsure/JMSPublisher.log", true);


logger.addHandler(handler);
}
catch(Exception e){
e.printStackTrace();
}
}

public void setSessionContext(SessionContext sc) {
this.sc = sc;
}


public void ejbCreate() {
Context context = null;
TopicConnectionFactory connFactory = null;


logger.info("In PublisherBean.ejbCreate()");

try {
context = new InitialContext();
topic = (Topic)context.lookup("topic/testTopic");

System.out.println(topic);

// Create a connection
connFactory = (TopicConnectionFactory)
context.lookup("java:/ConnectionFactory");

System.out.println(connFactory);

conn = connFactory.createTopicConnection();

System.out.println(conn);
}
catch (Throwable t) {
// JMSException or NamingException could be thrown
logger.severe("JMSPublisher.ejbCreate:" +
"Exception: " + t.toString());
}
}

private String chooseType() {
int whichMsg;
Random rgen = new Random();

whichMsg = rgen.nextInt(messageTypes.length);
return messageTypes[whichMsg];
}




public void publishMessages() {

TopicSession session = null;
TopicPublisher publisher = null;
TextMessage message = null;
int numMsgs = messageTypes.length * 3;
String messageType = null;

try {
session = conn.createTopicSession(true, 0);
publisher = session.createPublisher(topic);
message = session.createTextMessage();

for (int i = 0; i < numMsgs; i++) {
messageType = chooseType();
message.setStringProperty("NewsType",
messageType);
message.setText("This is a test JMS Message!!!" + i + ": " +
messageType);

//message.setText(msg + i + ": " +
// messageType);
//System.out.println("Starting Publishing JMS Message!!!");
logger.info("PUBLISHER: Setting " +
"message text to: " + message.getText());
try{
publisher.publish(topic, message);
//logger.info("PUBLISHER:"+ message +"successful published!");
}
catch(JMSException e){
logger.info("PUBLISHER:unsuccessful publishing!!!");
e.printStackTrace();
}
}

}
catch (Throwable t) {
// JMSException could be thrown
logger.severe("PublisherBean.publishNews: " +
"Exception: " + t.toString());
sc.setRollbackOnly();
}
finally {
if (session != null) {
try {
session.close();
}
catch (JMSException e) {}
}
}
}



public void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException {
System.out.println("In PublisherBean.ejbRemove()");

if (conn != null) {
try {
conn.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}

public void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
}

public void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
}


}

And ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>JMSPublisher</ejb-name>
<home>netsure.dat.adapterEngine.publisher.PublisherHome</home>
<remote>netsure.dat.adapterEngine.publisher.PublisherRemote</remote>
<ejb-class>netsure.dat.adapterEngine.publisher.JMSPublisherEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>

</enterprise-beans>
</ejb-jar>

and its jboss.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>JMSPublisher</ejb-name>
<jndi-name>dat/JMSPublisher</jndi-name>
</session>
</enterprise-beans>
</jboss>


JMS Receiver (MDB):

*/
public class JMSReceiverMDB implements MessageDrivenBean, MessageListener {

private MessageDrivenContext mdc = null;

static final Logger logger = Logger.getLogger("netsure.dat.adapterEngine.receiver.JMSReceiverMDB");

//public JMSReceiverMDB() {

// addLogger();

// logger.info("In MessageBean.MessageBean()");
// }

//private void addLogger(){
// try{
// FileHandler handler = new FileHandler("//home/netsure/JMSReceiver.log");

// logger.addHandler(handler);
// }
// catch(Exception e){
// e.printStackTrace();
// }
// }

public void setMessageDrivenContext(MessageDrivenContext mdc) throws javax.ejb.EJBException {
logger.info("In MessageBean.setMessageDrivenContext()");
this.mdc = mdc;
}

public void ejbCreate() {
logger.info("In MessageBean.ejbCreate()");
}

public void onMessage(Message inMessage) {
TextMessage msg = null;

try {

if (inMessage instanceof TextMessage) {
msg = (TextMessage) inMessage;
logger.info("MESSAGE BEAN: Message received: " + msg.getText());
}
else {
logger.warning("Message of wrong type: " +
inMessage.getClass().getName());
}
}
catch (JMSException e) {
logger.severe("MessageBean.onMessage: JMSException: " +
e.toString());
e.printStackTrace();
mdc.setRollbackOnly();
} catch (Throwable te) {
logger.severe("MessageBean.onMessage: Exception: " + te.toString());
te.printStackTrace();
}
}

public void ejbRemove() throws javax.ejb.EJBException {
logger.info("In MessageBean.remove()");
}

}

and its ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>JMSReceiver</ejb-name>
<ejb-class>netsure.dat.adapterEngine.receiver.JMSReceiverMDB</ejb-class>
<message-selector></message-selector>
<transaction-type>Container</transaction-type>
<acknowledge-mode>Auto-acknowledge</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
<subscription-durability>NonDurable</subscription-durability>
</message-driven-destination>
<resource-ref>
<res-ref-name>dat/TopicFacotry</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
</enterprise-beans>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>JMSReceiver</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>


and its jboss.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<enterprise-beans>
<message-driven>
<ejb-name>JMSReceiver</ejb-name>
<destination-jndi-name>topic/adapterEngine</destination-jndi-name>
<mdb-user>eyang</mdb-user>
<mdb-passwd>eyang01</mdb-passwd>
<!--<mdb-subscriber-id>DurableSubscriberEyang</mdb-subscriber-id>-->
<resource-ref>
<res-ref-name>dat/TopicFacotry</res-ref-name>
<jndi-name>java:/ConnectionFactory</jndi-name>
</resource-ref>
</message-driven>
</enterprise-beans>
</jboss>

Problem: Everything looks perfect. But I could not get any message on topic/testTopic monitored by HERMES Browser. And From JMX-Console, Session Bean has succesfully publishes messages, but MDB never activated. Where is the message? It disappears. What's the problem? Guys, I am very very appreciating hands from you!!! Please!!!

Thanking in advance.


Eddie
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your Topic JNDI lookup have the correct <resource-env-ref> entries?

And when you do a JNDI lookup for a TopicConnectionFactory, shouldn't the arg relate to this DD entry?

<res-ref-name>dat/TopicFacotry</res-ref-name>

Also, is there a typo, I'd have thought that the value should be dat/TopicFactory.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic