[jboss-user] [EJB/JBoss] - configuring remote topic host and port
sridummy
do-not-reply at jboss.com
Thu Oct 12 14:29:52 EDT 2006
Hi
Im using Jboss4.0.3SP1, Im very new to JMS&MDB's. I have written a MDB and a client which subscribes the msgs. I have to connect to the remote Topic which is in Seebeyond very old version and didnt have jndi.
The following is the code which i implemented for connecting to remote topic and ejb-jar.xml, jboss.xml
Im unable to listen to the messages after deploying the jar file.
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicPublisher;
import javax.jms.*;
import javax.ejb.*;
import javax.jms.TopicSession;
import javax.jms.TextMessage;
import com.seebeyond.jms.client.STCTopicConnectionFactory;
import com.seebeyond.jms.message.STCBytesMessage;
import com.seebeyond.jms.message.STCTextMessage;
/**
* @ejb.bean name="MyMBD1"
* display-name="Name for MyMBD1"
* description="Description for MyMBD1"
* destination-type="javax.jms.Topic"
* acknowledge-mode="Auto-acknowledge"
*/
public class MyMBD1 implements MessageDrivenBean, MessageListener {
MessageDrivenContext context = null;
String topicName = "etXMLShipmentOrder";
TopicConnectionFactory tcf = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
STCBytesMessage message = null;
InputStreamReader inputStreamReader = null;
char answer = '\0';
String hostName = "egludev07";
int port = 24820;
public MyMBD1() {
super();
System.out.println("Topic name is " + topicName);
// TODO Auto-generated constructor stub
}
public void setMessageDrivenContext(MessageDrivenContext context)
throws EJBException {
this.context = context;
System.out.println("Insdie setMessageDrivenContext ");
}
public void ejbRemove() throws EJBException {
System.out.println("ejbRemove ");
context = null;
if (topicConnection != null) {
try {
System.out.println("... Closing connection ...");
topicSession.commit();
topicConnection.close();
}catch(JMSException e){
System.out.println("Inside ejbRemove catch block ");
e.printStackTrace();
}
}
}
public void onMessage(Message message) {
System.out.println("onMessage");
STCTextMessage msg = null;
//final int MAX_MESSAGE_SIZE = 60;
try {
if (message instanceof TextMessage) {
msg = (STCTextMessage) message;
System.out.println(
"... Reading message: " + msg.getText());
} else {
System.out.println(
"Message of wrong type: "
+ message.getClass().getName());
}
topicSession.commit();
} catch (Exception e) {
System.out.println(
" JMSException in onMessage(): " + e.toString());
} catch (Throwable te) {
System.out.println(
"Exception in onMessage():" + te.getMessage());
}
}
/**
* Default create method
*
* @throws CreateException
*/
public void ejbCreate() {
System.out.println("Inside ejbCreate ");
try {
tcf = new STCTopicConnectionFactory(hostName, port);
topicConnection = tcf.createTopicConnection();
topicConnection.start();
topicSession =
topicConnection.createTopicSession(
true,
Session.AUTO_ACKNOWLEDGE);
topic = topicSession.createTopic(topicName);
topicSubscriber = topicSession.createDurableSubscriber(topic,"EAI_TEST_DURABLE");
} catch (Exception e){
System.out.println("Inside ejbCreateException Block "+e.getMessage());
e.getStackTrace();
}
}
}
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>MyMDB1</ejb-name>
<ejb-class>com.eagle.mdb.MyMBD1</ejb-class>
<transaction-type>Container</transaction-type>
<acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
</message-driven-destination>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
</enterprise-beans>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<enterprise-beans>
<message-driven>
<ejb-name>MyMDB1</ejb-name>
<destination-jndi-name>topic/testTopic</destination-jndi-name>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<jndi-name>TopicConnectionFactory</jndi-name>
</resource-ref>
</message-driven>
</enterprise-beans>
For my senario, pls guide me. Its very urgent.
Thanks in Advance
Sri
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977963#3977963
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977963
More information about the jboss-user
mailing list