You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by datafellow <da...@gmail.com> on 2007/01/08 19:30:51 UTC
newbee: pls help with stomp.py
Hi,
I am new to activemq/jms. I need one Producer with Java which seems to be
easy enough to create. But the Consumer needs to be in python as my effort
to integrate a java app with a python app. I am using the class embedded
broker and here is the code:
public class EmbeddedBroker {
public static void main(String[] args) throws Exception {
BrokerService broker = new BrokerService();
broker.setUseJmx(true);
broker.addConnector("tcp://localhost:61616");
broker.addConnector("stomp://localhost:61626");
broker.start();
// now lets wait forever to avoid the JVM terminating immediately
Object lock = new Object();
synchronized (lock) {
lock.wait();
}
}
}
The Producer in Java below:
public class Producer implements Runnable {
private String queueId = "FOO.BAR";
private String message = null;
public void run() {
try {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue(getQueueId());
// Create a MessageProducer from the Session to the Topic or
Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
if(Utils.isValidString(getMessage())) {
TextMessage message = session.createTextMessage(getMessage());
// Tell the producer to send the message
System.out.println("Sent message: "+ message.hashCode() + " : "
+ Thread.currentThread().getName());
producer.send(message);
}
// Clean up
session.close();
connection.close();
}
catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return the messages
*/
public List<String> getMessages() {
return messages;
}
/**
* @param messages the messages to set
*/
public void setMessages(List<String> messages) {
this.messages = messages;
}
/**
* @return the queueId
*/
public String getQueueId() {
return queueId;
}
/**
* @param queueId the queueId to set
*/
public void setQueueId(String queueId) {
this.queueId = queueId;
}
}
I am creating this Producer instance from this class:
public class App {
/**
* @param args
*/
public static void main(String[] args) {
Producer producer = new Producer();
for(int i = 0; i < 3; i++) {
producer.setMessage(msg + new Date());
thread(producer, false);
}
//thread(new Consumer(), false);
}
public static void thread(Runnable runnable, boolean daemon) {
Thread brokerThread = new Thread(runnable);
brokerThread.setDaemon(daemon);
brokerThread.start();
}
static String msg = "Hello Dear : ";
}
If I use a Java Consumer class, everything seems work but with stomp.py, it
does not seem to work. Here is the
code that I tried to write for using Stomp.py:
import Stomp
conn = Stomp.Connection('localhost', 61626, '', '')
conn.start()
this python code always shows these text and I get no more messages:
CONNECTED
session:ID:HRTUU21-1974-1168276980691-3:7
Please help me on this.
Thanks so much in advance.
--
View this message in context: http://www.nabble.com/newbee%3A-pls-help-with-stomp.py-tf2941085.html#a8223473
Sent from the ActiveMQ - User mailing list archive at Nabble.com.