Hi , i'm using openejb with activemq but they run on separate jvms.
i tried ;
on openejb jvm :
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class MonitoringTimerService {
@PostConstruct
private void init() {
final Hashtable<String, String> ctxProps = new Hashtable<String, String>(2);
ctxProps.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
ctxProps.put("java.naming.provider.url", "tcp://localhost:61616");
final InitialContext activeMQInitialContext = new InitialContext(ctxProps);
final javax.jms.ConnectionFactory factory = (javax.jms.ConnectionFactory)activeMQInitialContext.lookup("ConnectionFactory");
final Connection connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
topic = session.createTopic( "screenNotifications" );
producer = session.createProducer(topic);
}
@Lock(LockType.WRITE)
@Schedule(second="*/15", minute="*",hour="*",dayOfMonth = "*", persistent=false)
public void deleteLogs(){
//check if...
System.out.println("checking");
try {
TextMessage message = session.createTextMessage("Test 1 2 3");
producer.send(message);
} catch (JMSException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings
| File Templates.
}
System.out.println("done");
}
}
This code opens screenNotifications jms topic and sends message every 15 seconds like that
:
Then i've second java swing client that listens for messages from "screenNotifications" like
shown below :
InitialContext activeMQInitialContext = getActiveMQInitialContext();
javax.jms.ConnectionFactory factory = (javax.jms.ConnectionFactory)activeMQInitialContext.lookup("ConnectionFactory");
final Connection connection = factory.createConnection();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("screenNotifications");
// MessageConsumer is used for receiving (consuming) messages
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener( this );
@Override
public void onMessage(Message message) {
//To change body of implemented methods use File | Settings | File Templates.
System.out.println("Deneme");
}
But i dont get any message from openejb server although queue name with topic is same , whats
wrong ?
|