Skip to content

Instantly share code, notes, and snippets.

@dangnhdev
Last active April 28, 2016 17:43
Show Gist options
  • Save dangnhdev/a6be384682fc19722e511373a2c89b4d to your computer and use it in GitHub Desktop.
Save dangnhdev/a6be384682fc19722e511373a2c89b4d to your computer and use it in GitHub Desktop.
import com.rabbitmq.client.*;
public class Publisher {
private static final String EXCHANGE_NAME = "topic_test";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "topic");
String routingKey = "foo.bar";
String message = "TestMsg";
for (int i = 0; i < 1_000; i++) {
/*Persistent message*/
channel.basicPublish(EXCHANGE_NAME, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
System.out.println(" [x] Sent " + i);
}
connection.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment