vm://localhost will create a separate embedded broker for you that is
probably independent from the one the ajax app is using.
Refer to this thread for details:
http://www.nabble.com/app-to-web-demo-tf2193800.html#a6071268
jefetech wrote:
This is my broker:
private static final String BROKER_URL = "vm://localhost";
private static final String CHANNEL = "topic://CHAT.DEMO";
My console displays that the message was successfully sent, along with a
message ID, however my ajax listening window does not receive it. This
string message shoult spit out text in my Ajax listening console: <message
type='chat' from='" + from + "'>Hello World Yo!</message>
The ajax is working fine sending/receiving messages. It's just when I try
to do it in a Java class, it won't receive it. Thank you.
Adrian Co wrote:
Hi,
You don't need to simulate an httppost, since internally the ajax
messaging is still using JMS. (I'm assuming that you're using the
activemq-web libraries :)) Are you getting any exceptions? What's your
broker url?
Maybe you're running into this issue:
http://www.nabble.com/app-to-web-demo-tf2193800.html#a6071268
jefetech wrote:
I've got all my ajax send/receive working, however I need a java program
to
be able to send/receive message from the ajax. Why does the ajax not
receive this? Do I need simulate a httppost instead of this?
ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(BROKER_URL);
//Destination destination = client.getSession();
// 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.createTopic(CHANNEL);
// Create a MessageProducer from the Session to the Topic or
Queue
MessageProducer producer =
session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a messages
String from = Thread.currentThread().getName();
String text = "<message type='chat' from='" + from + "'>Hello
World Yo!</message>";
//String text = "Hello world! From: " +
Thread.currentThread().getName() + " : " + this.hashCode();
TextMessage message = session.createTextMessage(text);
// 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();