[jboss-user] [JBoss Messaging] - JBoss Settings for MDB Client ?
shptlucky
do-not-reply at jboss.com
Tue May 3 07:27:23 EDT 2011
shptlucky [http://community.jboss.org/people/shptlucky] created the discussion
"JBoss Settings for MDB Client ?"
To view the discussion, visit: http://community.jboss.org/message/603174#603174
--------------------------------------------------------------
I have made message driven bean.
I have made a producer class.
I am using Netbeans
Producer Class is sending message to local host and i am recieving it.
but i am not getting settings to be done for remote connection.
I am striving for last three weeks on it. Please anyone help and tell me what settings is required on client side or server for Remote JMS message retrieving. Code is here under:
*For Sending*
package com;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicConnection;
import javax.jms.TopicSession;
import javax.jms.TopicPublisher;
import javax.jms.Topic;
import javax.jms.TextMessage;
import javax.jms.Session;
import javax.jms.JMSException;
/**
* <p>Simple JMS client, publish text messages to testTopic Topic.
* </p>
*
* <p><b>NOTE</b>This code is a showcase only. It may not provide
* a stable production example.</p>
* @author Peter Antman
* @version $Revision: 3.1 $
*/
public class NewClass {
/**
* Topic connection, hold on to this so you may close it.
*/
TopicConnection topicConnection;
/**
* Topic session, hold on to this so you may close it.
* Also used to create messages.
*/
TopicSession topicSession;
/**
* Use this to publish messages.
*/
TopicPublisher topicPublisher;
/**
* Destination where to publish.
*/
Topic topic;
/**
* Sets up all the JMS fixtures.
*
* Use close() when finished with object.
*
* @param factoryJNDI name of the topic connection factory to look up.
* @param topicJNDI name of the topic destination to look up
*/
public NewClass(String factoryJNDI, String topicJNDI)
throws JMSException, NamingException {
// Populate with needed properties
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL, "192.168.1.218:1099");
props.put("java.naming.rmi.security.manager", "yes");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
// Get the initial context with given properties
Context context = new InitialContext(props);
System.out.println(factoryJNDI);
// Get the initial context
// Context context = new InitialContext();
// Get the connection factory
TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup("java:/XAConnectionFactory");
// Create the connection
topicConnection = topicFactory.createTopicConnection();
// Create the session
topicSession = topicConnection.createTopicSession(
// No transaction
false,
// Auto ack
Session.AUTO_ACKNOWLEDGE);
// Look up the destination
topic = (Topic) context.lookup(topicJNDI);
// Create a publisher
topicPublisher = topicSession.createPublisher(topic);
}
/**
* Publish the given String as a JMS message to the testTopic topic.
*/
public void publish(String msg) throws JMSException {
// Create a message
TextMessage message = topicSession.createTextMessage();
message.setText(msg);
// Publish the message
topicPublisher.publish(topic, message);
}
/**
* Close session and connection.
* When done, no publishing is possible any more.
*/
public void close() throws JMSException {
topicSession.close();
topicConnection.close();
}
/**
* Run an example publishing 10 messages to testTopic.
* Only works up to and including JBoss 2.4.0
*/
public static void main(String[] args) {
try {
// Create the HelloPublisher, giving it the name of the
// TopicConnection Factory and the Topic destination to
// use in lookup.
NewClass publisher = new NewClass("ConnectionFactory","topic/testTopic1");
// Publish 10 messages
for (int i = 1; i < 11; i++) {
String msg = "Hello World no. " + i;
System.out.println("Publishing message: " + msg);
publisher.publish(msg);
}
// Close down your publisher
publisher.close();
}
catch (Exception ex)
{
System.err.println("An exception occurred while testing HelloPublisher: " + ex);
ex.printStackTrace();
}
}
} // HelloPublisher
*MDB For reciving on Client End*
package com;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
@MessageDriven(mappedName = "topic/testTopic",
activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/testTopic"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "NonDurable"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "DrivenBean6"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "DrivenBean6")
})
public class DrivenBean implements MessageListener {
public DrivenBean() {
}
TextMessage tx=null;
public void onMessage(Message message)
{
tx=(TextMessage) message;
try {
System.out.println("Driven Bean -> " + tx.getText());
} catch (JMSException ex) {
}
System.out.println("Hello");
}
}
What Settings are required so that i could send message to client end.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/603174#603174]
Start a new discussion in JBoss Messaging at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110503/fd3a1020/attachment-0001.html
More information about the jboss-user
mailing list