Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. queue_pending1 ---> dequeue -----> process#1 -----> enqueue -----> queue_processed.
  2. queue_pending2 ---> dequeue -----> process#2 -----> enqueue -----> queue_processed.
  3.  
  4. queue_pending1: Pending(0), Enqueued(100), Dequeued(100)
  5. queue_pending2: Pending(0), Enqueued(100), Dequeued(100)
  6. queue_processed: Pending(200), Enqueued(200), Dequeued(0)
  7.  
  8. queue_pending1: Pending(0), Enqueued(100), Dequeued(100)
  9. queue_pending2: Pending(5), Enqueued(100), Dequeued(95)
  10. queue_processed: Pending(200), Enqueued(200), Dequeued(0)
  11.  
  12. /**
  13. * @throws JMSException
  14. * , Exception
  15. */
  16. private void setUpActiveMQConnection() throws JMSException {
  17. connectionFactory = new ActiveMQConnectionFactory(this.activeMQUser,
  18. this.activeMQPassword, this.activeMQURI);
  19. try {
  20.  
  21. connection = connectionFactory.createConnection();
  22. connection.start();
  23. //transacted = false
  24. session = connection.createSession(transacted,
  25. Session.AUTO_ACKNOWLEDGE);
  26. isConnected = true;
  27. } catch (JMSException e) {
  28. isConnected = false;
  29. throw e;
  30. }
  31. }
  32.  
  33. /**
  34. * @throws Exception
  35. */
  36. private void createQueue() throws JMSException {
  37. try {
  38. if (destinationQueue == null) {
  39. destinationQueue = session.createQueue(this.activeMQQueueName);
  40. isQueueAvailable = true;
  41. }
  42. } catch (JMSException e) {
  43. isQueueAvailable = false;
  44. throw e;
  45. }
  46. }
  47.  
  48. /**
  49. * @throws JMSException
  50. *
  51. */
  52. private void createProducer() throws JMSException {
  53. if (producerForQueue == null) {
  54. try {
  55. producerForQueue = session.createProducer(destinationQueue);
  56. producerForQueue.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
  57. isProducerAvailable = true;
  58. } catch (JMSException e) {
  59. isProducerAvailable = false;
  60. throw e;
  61. }
  62. }
  63. }
  64.  
  65. /**
  66. * @throws JMSException
  67. */
  68. private void createConsumer() throws JMSException {
  69. if (consumerForQueue == null) {
  70. try {
  71. consumerForQueue = session.createConsumer(destinationQueue);
  72. isConsumerAvailable = true;
  73. } catch (JMSException e) {
  74. isConsumerAvailable = false;
  75. throw e;
  76. }
  77. }
  78. }
  79.  
  80. /*
  81. * (non-Javadoc)
  82. *
  83. */
  84. @Override
  85. public void sendMessage(Serializable objectToQueue) throws JMSException {
  86. ObjectMessage message = session.createObjectMessage();
  87. message.setObject(objectToQueue);
  88. producerForQueue.send(message);
  89. }
  90.  
  91. /*
  92. * (non-Javadoc)
  93. *
  94. * @see example.jms.impl.JMSConnection#receiveMessage()
  95. */
  96. @Override
  97. public Serializable receiveMessage() throws JMSException {
  98. Message message = consumerForQueue.receive(timeout);
  99. if (message instanceof ObjectMessage) {
  100. ObjectMessage objMsg = (ObjectMessage) message;
  101. Serializable sobject = objMsg.getObject();
  102. return sobject;
  103. }
  104. return null;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement