Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package org.jboss.fuse.qa.tools.jms;
  2.  
  3. import org.apache.activemq.ActiveMQConnectionFactory;
  4.  
  5. import javax.jms.Connection;
  6. import javax.jms.ConnectionFactory;
  7. import javax.jms.JMSException;
  8. import javax.jms.Message;
  9. import javax.jms.Session;
  10.  
  11. import java.util.stream.IntStream;
  12.  
  13. /**
  14. * @author Josef Ludvicek
  15. */
  16. public class GenerateAMQQueues {
  17. public static void main(String[] args) throws JMSException {
  18.  
  19. String host = "localhost";
  20. int port = 61616;
  21. String username = "admin";
  22. String password = "admin";
  23.  
  24. String url = String.format("tcp://%s:%s", host, port);
  25.  
  26. ConnectionFactory cf = new ActiveMQConnectionFactory(username, password, url);
  27. Connection c = cf.createConnection();
  28.  
  29. c.start();
  30.  
  31. Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
  32.  
  33. Message m = s.createTextMessage("This is init message");
  34.  
  35. IntStream.range(1, 2010)
  36. // counter -> queue string name
  37. .mapToObj(i -> String.format("generated.queue.%04d", i))
  38. // create destination from queue name
  39. .map(queueName -> {
  40. try {
  41. return s.createProducer(s.createQueue(queueName));
  42. } catch (JMSException e) {
  43. throw new RuntimeException("failed to create producer: " + e.getMessage(), e);
  44. }
  45. })
  46.  
  47. .forEach(messageProducer -> {
  48. try {
  49. System.out.println("sending to " + messageProducer.getDestination().toString());
  50. messageProducer.send(m);
  51. } catch (JMSException e) {
  52. throw new RuntimeException("failed to send message: " + e.getMessage(), e);
  53. }
  54. });
  55.  
  56. c.close();
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement