activemq queue issue

I am trying below 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();
		//Creating a non transactional session to send/receive JMS message.
		Session session = connection.createSession(false,
		//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!
		System.out.println("JCG printing@@ '" + message.getText() + "'");

Open in new window

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

please advise
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.