-
1. Re: Integration Jboss 7 -- Tomcat 7 with Jms
wdfink Jan 3, 2014 5:21 AM (in response to ccontreras)I suppose you use a wrong InitialContext. It will be different for EJB and other JNDI stuff.
Have a look to jboss-eap-quickstarts/helloworld-jms
-
2. Re: Re: Integration Jboss 7 -- Tomcat 7 with Jms
ccontreras Jan 3, 2014 7:55 AM (in response to wdfink)Hello Wolf-Dieter. Thank you for the response.
I watched this example and i haven´t problem to send the event. The problem is that my client is in a Tomcat, out of the Jboss. Can i have diferent InitialContext in the same aplication? Can be the problem that i haven´t configuration QHornet in Tomcat? What do you think?
Thank you very much.
-
3. Re: Integration Jboss 7 -- Tomcat 7 with Jms
wdfink Jan 3, 2014 9:58 AM (in response to ccontreras)1 of 1 people found this helpfulFor one InitialContext you can set the "org.jboss.ejb.client.naming" to support EJB.
The other InitialContext include the remote-naming approach (there is no *ejb* property) as it's shown in the JMS quickstart.
You should not mix the properties in the same InitialContext, but you can use multiple IC's in the same JVM
-
4. Re: Integration Jboss 7 -- Tomcat 7 with Jms
ccontreras Jan 5, 2014 7:39 AM (in response to wdfink)Hello wfink
Thank you very much for the answer. Finally, i found the problem. The problem was that I put in the System.properties the property "java.naming.provider.url" before to create the InitialContext for the JMS connection. Now, I´m writing the InitialContext for the JMS before put this property and now works.
But now, i have other problem. I need create a MessageListener that catch the event. My program´s code is:
======================================
===== SERVER ======
======================================
Context jndiContext = oLocator.getContexto();
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) jndiContext
.lookup(Global.NOMBRE_CONECTION_FACTORY_JMS);
QueueConnection queueConnection = queueConnectionFactory
.createQueueConnection("cam", "cam");
QueueSession qsession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue q = (Queue) jndiContext.lookup(Global.NOMBRE_COLA_JMS);
QueueSender qsender = qsession.createSender(q);
queueConnection.start();
ObjectMessage message = qsession.createObjectMessage();
HashMap<String, Object> map = new HashMap<String, Object>();
message.setJMSType("alta.intercambio");
map.put("usuario", usuario);
message.setObject(map);
qsender.send(message, DeliveryMode.PERSISTENT,
Message.DEFAULT_PRIORITY, 7 * 24 * 3600 * 1000L);
qsender.close();
qsession.close();
queueConnection.close();
======================================
===== CLIENT ======
======================================
public void crearJms() {
try {
// Set up the context for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL,
System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
env.put(Context.SECURITY_PRINCIPAL,
System.getProperty("username", "cam"));
env.put(Context.SECURITY_CREDENTIALS,
System.getProperty("password", "cam"));
InitialContext context = new InitialContext(env);
// Perform the JNDI lookups
String connectionFactoryString = System.getProperty(
"connection.factory", DEFAULT_CONNECTION_FACTORY);
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context
.lookup(connectionFactoryString);
String destinationString = System.getProperty("destination",
DEFAULT_DESTINATION);
Destination destination = (Destination) context
.lookup(destinationString);
// Create the JMS connection, session, producer, and consumer
connection = queueConnectionFactory.createQueueConnection(
System.getProperty("username", DEFAULT_USERNAME),
System.getProperty("password", DEFAULT_PASSWORD));
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(destination);
session.recover();
consumer.setMessageListener(new UserQueueReceiverAdapter());
connection.start();
} catch (Exception ex) {
System.out.println("Error " + ex);
} finally {
if (connection != null) {
try {
connection.close();
} catch (Exception ex) {
System.out.println("Error cerrando " + ex);
}
}
}
}
=================================================
===== LISTENER IN THE CLIENT =====
=================================================
public class UserQueueReceiverAdapter implements MessageListener {
/**
* Recibe los mensajes enviados al cliente
*
* @param message
* Message
*/
public void onMessage(Message oMensaje) {
try {
String JMSType = oMensaje.getJMSType();
if (JMSType.equals("alta.intercambio")) {
ObjectMessage objectMessage = (ObjectMessage) oMensaje;
Map args = (Map) objectMessage.getObject();
}
} catch (JMSException ex) {
Mensajes.mostrarMensajeError("Error al recibir el mensaje." + ex,
null);
}
}
}
===========================================
But the class UserQueueReceiverAdapter don´t catch nothing.
Have you any idea? Can you help me?
Thank you very much!