I am doing some exercises on JMS in Spring and I have some doubt.
Into the solution of an exercise I have this configuration class named JmsInfrastructureConfig:
package config;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JmsInfrastructureConfig {
/**
* Create a ConnectionFactory using ActiveMQ:
*/
@Bean
public ConnectionFactory connectionFactory(){
return new ActiveMQConnectionFactory("vm://embedded?broker.persistent=false");
}
/**
* Create a Queue for Dining objects using ActiveMQ:
*/
@Bean
public Destination diningQueue() {
return new ActiveMQQueue("rewards.queue.dining");
}
/**
* Create a Queue for Confirmation objects using ActiveMQ:
*/
@Bean
public Destination confirmationQueue() {
return new ActiveMQQueue("rewards.queue.confirmation");
}
}
I know that in JMS-based applications the Connection object is obtained from a ConnectionFactory.
From what I understand reading the documentation the Connection is one of the JMS core components and it is used to put messages into a queue\topic and to consume a messages from a queue\topic. Is this assertion true or this is a wrong assertion?
The JMS Connection is obtained from a factory object, so in the previous configuration class is declared this bean that create and return the specific factory:
@Bean
public ConnectionFactory connectionFactory(){
return new ActiveMQConnectionFactory("vm://embedded?broker.persistent=false");
}
It is pretty clear for me but here I have my first doubt. It create a new ActiveMQConnectionFactory object because it is used Apache Active MQ as Message Oriented Middleware.
What exactly do Apache Active MQ (and a MOM in general)? It handle the queues and topics and the access to these objects?).
What exactly is vm://embedded?broker.persistent=false ? Is it the broker URL? how exactly have I to interpret this address?
Then into the JmsInfrastructureConfig class create these 2 beans:
// Create a Queue for Dining objects using ActiveMQ:
@Bean
public Destination diningQueue() {
return new ActiveMQQueue("rewards.queue.dining");
}
// Create a Queue for Confirmation objects using ActiveMQ:
@Bean
public Destination confirmationQueue() {
return new ActiveMQQueue("rewards.queue.confirmation");
}
Both creates a specific queue, named respectivelly: rewards.queue.dining and rewards.queue.confirmation (I think that these are the queues name, or not?)
So these beans create a queue where the producer can put a message and from what a consumer can read a message.
These methods return a Destination object, what exactly represent this object? Is it the gateway to access to the queue (where access means write on read from the queue)? Or what?
Another doubt is: why in the acrhitecture of this application the declaration of the bean that return a ConnectionFactory is in the same class where are definied the beans that creats queues?