Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- queue_pending1 ---> dequeue -----> process#1 -----> enqueue -----> queue_processed.
- queue_pending2 ---> dequeue -----> process#2 -----> enqueue -----> queue_processed.
- queue_pending1: Pending(0), Enqueued(100), Dequeued(100)
- queue_pending2: Pending(0), Enqueued(100), Dequeued(100)
- queue_processed: Pending(200), Enqueued(200), Dequeued(0)
- queue_pending1: Pending(0), Enqueued(100), Dequeued(100)
- queue_pending2: Pending(5), Enqueued(100), Dequeued(95)
- queue_processed: Pending(200), Enqueued(200), Dequeued(0)
- /**
- * @throws JMSException
- * , Exception
- */
- private void setUpActiveMQConnection() throws JMSException {
- connectionFactory = new ActiveMQConnectionFactory(this.activeMQUser,
- this.activeMQPassword, this.activeMQURI);
- try {
- connection = connectionFactory.createConnection();
- connection.start();
- //transacted = false
- session = connection.createSession(transacted,
- Session.AUTO_ACKNOWLEDGE);
- isConnected = true;
- } catch (JMSException e) {
- isConnected = false;
- throw e;
- }
- }
- /**
- * @throws Exception
- */
- private void createQueue() throws JMSException {
- try {
- if (destinationQueue == null) {
- destinationQueue = session.createQueue(this.activeMQQueueName);
- isQueueAvailable = true;
- }
- } catch (JMSException e) {
- isQueueAvailable = false;
- throw e;
- }
- }
- /**
- * @throws JMSException
- *
- */
- private void createProducer() throws JMSException {
- if (producerForQueue == null) {
- try {
- producerForQueue = session.createProducer(destinationQueue);
- producerForQueue.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- isProducerAvailable = true;
- } catch (JMSException e) {
- isProducerAvailable = false;
- throw e;
- }
- }
- }
- /**
- * @throws JMSException
- */
- private void createConsumer() throws JMSException {
- if (consumerForQueue == null) {
- try {
- consumerForQueue = session.createConsumer(destinationQueue);
- isConsumerAvailable = true;
- } catch (JMSException e) {
- isConsumerAvailable = false;
- throw e;
- }
- }
- }
- /*
- * (non-Javadoc)
- *
- */
- @Override
- public void sendMessage(Serializable objectToQueue) throws JMSException {
- ObjectMessage message = session.createObjectMessage();
- message.setObject(objectToQueue);
- producerForQueue.send(message);
- }
- /*
- * (non-Javadoc)
- *
- * @see example.jms.impl.JMSConnection#receiveMessage()
- */
- @Override
- public Serializable receiveMessage() throws JMSException {
- Message message = consumerForQueue.receive(timeout);
- if (message instanceof ObjectMessage) {
- ObjectMessage objMsg = (ObjectMessage) message;
- Serializable sobject = objMsg.getObject();
- return sobject;
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement