[英]How exactly works this configuration that definies the JMS infrastracture into a Spring application?
I am doing some exercises on JMS in Spring and I have some doubt. 我在春季在JMS上进行一些练习,我对此有些怀疑。
Into the solution of an exercise I have this configuration class named JmsInfrastructureConfig : 在练习的解决方案中,我有一个名为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 . 我知道在基于JMS的应用程序中, Connection对象是从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. 据我了解的阅读文档, 连接是JMS核心组件之一 ,它用于将消息放入queue \\ topic并使用来自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: JMS 连接是从工厂对象获得的,因此在先前的配置类中,此bean声明为创建并返回特定工厂的bean:
@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 . 它创建一个新的ActiveMQConnectionFactory对象,因为它将Apache Active MQ用作面向消息的中间件 。
What exactly do Apache Active MQ (and a MOM in general)? Apache Active MQ (通常是MOM )到底是什么? It handle the queues and topics and the access to these objects?). 它处理队列和主题以及对这些对象的访问?)。
What exactly is vm://embedded?broker.persistent=false ? 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: 然后在JmsInfrastructureConfig类中创建以下两个bean:
// 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?) 两者都创建一个特定的队列 ,分别命名为: rewards.queue.dining和rewards.queue.confirmation (我认为这些是队列名称,还是不是?)
So these beans create a queue where the producer can put a message and from what a consumer can read a message. 因此,这些bean创建了一个队列,生产者可以在该队列中放置一条消息,而消费者可以从中读取消息。
These methods return a Destination object, what exactly represent this object? 这些方法返回一个Destination对象,该对象究竟代表什么? 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? 另一个疑问是:为什么在此应用程序的体系结构中,返回ConnectionFactory的bean的声明在与定义创建队列的bean相同的类中?
Is it used to put messages into a queue\\topic and to consume? 它是否用于将消息放入队列\\主题并进行消费?
Yes, it is. 是的。
What exactly is vm://embedded?broker.persistent=false vm:// embedded?broker.persistent = false到底是什么
This is your brokerURL, and this is how you should interpret it: 这是您的brokerURL,这是您应该如何解释的网址:
I think that these are the queues name 我认为这些是队列名称
Yes, these are your queues. 是的,这些是您的队列。
Destination 目的地
This is the object you can use to access your queue. 这是您可以用来访问队列的对象。 By using it you can produce (send) or consume (read) messages. 通过使用它,您可以生成(发送)或使用(读取)消息。
why in the architecture of this application the declaration of the bean that return a ConnectionFactory is in the same class where are defined the beans that creats queues? 为什么在此应用程序的体系结构中,返回ConnectionFactory的bean的声明位于定义了创建队列的bean的同一类中?
They do not have be necessarily in the same class. 它们不一定必须在同一类中。 However that example aims to be as simple as it can, so it creates these queues for you on the spot, so you can use it. 但是,该示例的目的是尽可能简单,因此它为您现场创建了这些队列,因此您可以使用它。
What exactly do Apache Active MQ (and a MOM in general)? Apache Active MQ(通常是MOM)到底是什么? It handle the queues and topics and the access to these objects?). 它处理队列和主题以及对这些对象的访问?)。
I think it is way too broad a question to answer. 我认为这个问题回答的范围太广了。 If you need a very highlevel explanation, you should probably read something first, like this: Message broker 如果您需要一个非常高级的说明,则可能应该先阅读一些内容,例如: 消息代理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.