Advertisement
Guest User

s

a guest
Jun 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. public MessageSenderGateway(String queueName) {
  2. if (queueName != null) {
  3. try {
  4. Properties props = new Properties();
  5. props.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
  6. props.setProperty("java.naming.provider.url", "tcp://localhost:61616");
  7. props.put("queue." + queueName, queueName);
  8. Context jndiContext = new InitialContext(props);
  9. ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext.lookup("ConnectionFactory");
  10. this.connection = connectionFactory.createConnection();
  11. this.session = this.connection.createSession(false, 1);
  12. this.producer = this.session.createProducer((Destination)null);
  13. this.destination = (Destination)jndiContext.lookup(queueName);
  14. this.connection.start();
  15. } catch (JMSException | NamingException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19.  
  20. }
  21.  
  22.  
  23. public MessageReceiverGateway(String queueName) {
  24. if (queueName != null) {
  25. try {
  26. Properties props = new Properties();
  27. props.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
  28. props.setProperty("java.naming.provider.url", "tcp://localhost:61616");
  29. props.put("queue." + queueName, queueName);
  30. Context jndiContext = new InitialContext(props);
  31. ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext.lookup("ConnectionFactory");
  32. this.connection = connectionFactory.createConnection();
  33. this.session = this.connection.createSession(false, 1);
  34. this.destination = (Destination)jndiContext.lookup(queueName);
  35. this.consumer = this.session.createConsumer(this.destination);
  36. this.connection.start();
  37. } catch (JMSException | NamingException e) {
  38. e.printStackTrace();
  39. }
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement