当前位置: 首页 > ActiveMQ in Action 读书笔记 > 正文

5.5 内存消息存储-The memory message store

The memory message store holds all persistent messages in memory. No active caching

is involved, so you have to be careful that both the JVM and the memory limits you

set for the broker are large enough to accommodate all the messages that may exist in

this message store at one time.

 

内存消息存储将所有的持久化消息放到内存中.内存消息存储没有活动的缓存,你必须小心的设置JVM以及

内存大小限制,以便代理有足够的内存容纳所有的消息.

 

The memory message store can be useful if you know that the broker will only

store a finite amount of messages, which will typically be consumed quickly. But it

really comes into its own for small test cases, where you want to prove interaction with

a JMS broker, but don’t want to incur the cost of a message store start time, or the hassle

of cleaning up the message store after the test has finished.

 

当你确定代理只会存储有限容量的消息时,内存消息存储将会变得很有用,此时消息分发速度将会非常快.

但是内存消息存储一般用于小规模的测试,即,你打算测试与JMS代理的交互,但不想在代理的

消息存储启动时多花时间,或者不想在测试结束后卷入清理消息存储的麻烦中.

 

5.5.1 Configuring the memory store

5.5.1 配置内存消息存储

 

Configuring the memory store is simple. The memory store is the implementation

used when the broker property named persistent is set to false (the default is true).

Here’s an example of configuration which enables use of the ActiveMQ message store:

 

配置内存消息存储很简单.配置内存消息存储是只需要将broker的persistent属性值设置为false

(该属性默认值为true).下面是配置ActiveMQ内存消息存储示例:

 

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans>

<broker brokerName=”test-broker” persistent=”false” xmlns=”http://activemq.apache.org/schema/core”>

<transportConnectors>

<transportConnector uri=”tcp://localhost:61635″/>

</transportConnectors>

</broker>

</beans>

 

By setting the persistent attribute on the broker element to false, this effectively tells

the broker not to persist messages to long-term storage. Instead, the ActiveMQ broker

will hold messages in memory until the messages are either consumed or the

ActiveMQ broker is shut down.

 

通过设置broker元素的persistent属性值为false,有效的通知代理不用持久化消息到长期存储介质中.

相反的,ActiveMQ代理会将消息保存到内存中,直到消息被消息消费者处理或者ActiveMQ代理关闭.

 

Embedding an ActiveMQ broker with the memory store is easy. The following

example starts a broker with the memory store:

通过代码启动一个使用内存消息存储的ActiveMQ代理十分容易.下面的通过代码示例如何

启动一个使用内存消息存储的代理:

 

import org.apache.activemq.broker.BrokerService;

public void createEmbeddedBroker() throws Exception

{

BrokerService broker = new BrokerService();

//configure the broker to use the Memory Store

broker.setPersistent(false);

//Add a transport connector

broker.addConnector(“tcp://localhost:61616”);

//now start the broker

broker.start();

}

 

Note the bold text that sets persistence to false on the broker object. This is equivalent

to the previous XML configuration example.

注意,上面斜体部分设置broker对象持久化属性为false,这跟在前面XML文件中的配置是等价的.

 

There are currently no utilities to change from one type of ActiveMQ message

store to another. If you want to change message stores for an application, it’s recommended

that you only do so on a new ActiveMQ broker, or wait until your application

has consumed all the messages sent, then close down the ActiveMQ broker, reconfigure

it for a new message store, and restart it.

 

目前没有必要修改ActiveMQ的消息存储.如果你打算为一个应用程序修改消息存储,推荐使用一个新的

ActiveMQ代理,或者等到你的程序处理了所有已发送的消息,然后关闭ActiveMQ代理,然后配置新的

消息存储,最后重启代理.

 

This concludes the discussion of the various message store implementations for

message persistent in ActiveMQ. Another topic that bears some discussion regarding

message persistence is a more specialized case for caching messages in the ActiveMQ

broker for nondurable topic subscribers.

 

到这里,讨论ActiveMQ消息存储的各种实现就告一段落了.处理消息持久化,另外一个值得讨论的话题是

ActiveMQ如何为非持久化的消息主题订阅者缓存消息.

打个赏呗

   微信打赏  支付宝打赏


本文固定链接: https://www.jack-yin.com/coding/translation/activemq-in-action/770.html | 边城网事

该日志由 边城网事 于2013年10月18日发表在 ActiveMQ in Action 读书笔记 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 5.5 内存消息存储-The memory message store | 边城网事
关键字: ,

5.5 内存消息存储-The memory message store 暂无评论

发表评论

快捷键:Ctrl+Enter