Created
February 20, 2016 17:26
-
-
Save kiichi/ce8a59ed9fb4539c4ba2 to your computer and use it in GitHub Desktop.
RabbitMQ Sample in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.rabbitmq.client.ConnectionFactory; | |
| import com.rabbitmq.client.Connection; | |
| import com.rabbitmq.client.Channel; | |
| // See python code comment for username / password settings | |
| //javac -cp rabbitmq-client.jar Send.java | |
| //java -cp .:./rabbitmq-client.jar Send | |
| public class Send { | |
| private final static String QUEUE_NAME = "javahello"; | |
| public static void main(String[] argv) throws Exception { | |
| String server = "192.168.64.2"; | |
| ConnectionFactory factory = new ConnectionFactory(); | |
| factory.setHost(server); | |
| factory.setUsername("test"); | |
| factory.setPassword("test"); | |
| Connection connection = factory.newConnection(); | |
| Channel channel = connection.createChannel(); | |
| channel.queueDeclare(QUEUE_NAME, false, false, false, null); | |
| String message = "Hello From Java!"; | |
| channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); | |
| System.out.println(" [x] Sent '" + message + "'"); | |
| channel.close(); | |
| connection.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment