Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jboss.fuse.qa.tools.jms;
- import org.apache.activemq.ActiveMQConnectionFactory;
- import javax.jms.Connection;
- import javax.jms.ConnectionFactory;
- import javax.jms.JMSException;
- import javax.jms.Message;
- import javax.jms.Session;
- import java.util.stream.IntStream;
- /**
- * @author Josef Ludvicek
- */
- public class GenerateAMQQueues {
- public static void main(String[] args) throws JMSException {
- String host = "localhost";
- int port = 61616;
- String username = "admin";
- String password = "admin";
- String url = String.format("tcp://%s:%s", host, port);
- ConnectionFactory cf = new ActiveMQConnectionFactory(username, password, url);
- Connection c = cf.createConnection();
- c.start();
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Message m = s.createTextMessage("This is init message");
- IntStream.range(1, 2010)
- // counter -> queue string name
- .mapToObj(i -> String.format("generated.queue.%04d", i))
- // create destination from queue name
- .map(queueName -> {
- try {
- return s.createProducer(s.createQueue(queueName));
- } catch (JMSException e) {
- throw new RuntimeException("failed to create producer: " + e.getMessage(), e);
- }
- })
- .forEach(messageProducer -> {
- try {
- System.out.println("sending to " + messageProducer.getDestination().toString());
- messageProducer.send(m);
- } catch (JMSException e) {
- throw new RuntimeException("failed to send message: " + e.getMessage(), e);
- }
- });
- c.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement