I tried some more stuff, and I came up with this code:
Code:
package nl.jworks.rabbitmq;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
public class Send {
private final static String QUEUE_NAME = "newQueueName";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
System.out.println("Close channel");
connection.close();
System.out.println("Close connection");
System.out.println("Exit");
}
}
To send a message to RabbitMQ. This works a little bit: when I run the following, the queue name is created, and the message is sent, but the application hangs at the 'channel.close()'. The 'close channel' message is never printed to the console. I'm still trying to figure out why the Java version doesn't work, and the command line does...
Erik