Guest User

Untitled

a guest
Dec 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import static org.mule.runtime.extension.api.annotation.param.MediaType.ANY;
  2.  
  3. import org.mule.runtime.extension.api.annotation.param.Config;
  4.  
  5. import org.mule.runtime.extension.api.annotation.param.MediaType;
  6.  
  7.  
  8. //
  9.  
  10. import javax.jms.ConnectionFactory;
  11. import javax.jms.Destination;
  12. import javax.jms.JMSException;
  13. import javax.jms.MessageProducer;
  14. import javax.jms.Session;
  15. import javax.jms.TextMessage;
  16.  
  17. import org.apache.activemq.ActiveMQConnection;
  18. import org.apache.activemq.ActiveMQConnectionFactory;
  19.  
  20. public class ProduceOperations {
  21.  
  22. @MediaType(value = ANY, strict = false)
  23. public void produceInfo(@Config AdvanceConfiguration configuration) throws JMSException{
  24.  
  25. // URL of the JMS server. DEFAULT_BROKER_URL will just mean
  26. // that JMS server is on localhost
  27. String url = ActiveMQConnection.DEFAULT_BROKER_URL;
  28. // default broker URL is : tcp://localhost:61616"
  29.  
  30. String subject = "gslab"; //Queue Name
  31. // You can create any/many queue names as per your requirement.
  32.  
  33.  
  34. // Getting JMS connection from the server and starting it
  35. ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
  36. javax.jms.Connection connection = connectionFactory.createConnection();
  37. connection.start();
  38. // JMS messages are sent and received using a Session. We will
  39. // create here a non-transactional session object. If you want
  40. // to use transactions you should set the first parameter to 'true'
  41. Session session = connection.createSession(false,
  42. Session.AUTO_ACKNOWLEDGE);
  43. // Destination represents here our queue 'VALLYSOFTQ' on the
  44. // JMS server. You don't have to do anything special on the
  45. // server to create it, it will be created automatically.
  46. Destination destination = session.createQueue(subject);
  47. // MessageProducer is used for sending messages (as opposed
  48. // to MessageConsumer which is used for receiving them)
  49. MessageProducer producer = session.createProducer(destination);
  50. // We will send a small text message saying 'Hello' in Japanese
  51. TextMessage message = session.createTextMessage(configuration.getMessage());
  52. //TextMessage message = session.createTextMessage("Hello welcome come to vallysoft ActiveMQ!");
  53. // Here we are sending the message!
  54. producer.send(message);
  55. System.out.println("Sentage '" + message.getText() + "'");
  56.  
  57. connection.close();
  58. }
  59.  
  60.  
  61. }
Add Comment
Please, Sign In to add comment