• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 85
  • Last Modified:

activemq queue issue

I am trying below example

https://examples.javacodegeeks.com/enterprise-java/jms/apache-activemq-hello-world-example/


When i try to run the MEssageSender class how it ran even though there is existing Queue on ActiveMQ called JCG_QUEUE

package com.activemq.sender;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class MessageSender {
	
	//URL of the JMS server. DEFAULT_BROKER_URL will just mean that JMS server is on localhost
	private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
	
	// default broker URL is : tcp://localhost:61616"
	private static String subject = "JCG_QUEUE"; // Queue Name.You can create any/many queue names as per your requirement.	
	
	public static void main(String[] args) throws JMSException {		
		// Getting JMS connection from the server and starting it
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
		Connection connection = connectionFactory.createConnection();
		connection.start();
		
		//Creating a non transactional session to send/receive JMS message.
		Session session = connection.createSession(false,
				Session.AUTO_ACKNOWLEDGE);	
		
		//Destination represents here our queue 'JCG_QUEUE' on the JMS server. 
		//The queue will be created automatically on the server.
		Destination destination = session.createQueue(subject);	
		
		// MessageProducer is used for sending messages to the queue.
		MessageProducer producer = session.createProducer(destination);
		
		// We will send a small text message saying 'Hello World!!!' 
		TextMessage message = session
				.createTextMessage("Hello !!! Welcome to the world of ActiveMQ.");
		
		// Here we are sending our message!
		producer.send(message);
		
		System.out.println("JCG printing@@ '" + message.getText() + "'");
		connection.close();
	}
}

Open in new window


in my code it was never said if queue already there delete and recreate etc?

please advise
0
gudii9
Asked:
gudii9
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
A JMS client never creates a Queue directly. The createQueue method is a bit misleading, it doesn't create the queue on the server, it just creates the "Queue" object for use by your client code.

Typically, the JMS MQ administrator creates all the queues that are required, as an administrative task. However, ActiveMQ has a specific way that it can be configured (and it is this way by default) where it will automatically create a queue when the first messge is sent to it, or when the first receiver listening to a queue starts up. If the queue is already existing, it will just use that queue straight away.


in my code it was never said if queue already there delete and recreate etc?

Note, it DIDN'T delete and recreate, it just used the existing queue.


Hopefully, this all helps to explain what you are seeing. Let us know if you still have questions.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now