チームのアプリの 1 つのキューイング ソリューションを研究しています。理想的には、軽量のインプロセス ブローカー (スレッド間の低スループット メッセージング用) と外部ブローカーの両方として構成できるものが必要です。これを実行できる MQ サーバーはありますか? ほとんどの場合、外部エンティティとして設定する必要があるようです。ZeroMQ はインプロセス ソリューションに最も近いように見えますが、「強化された UDP ソケット」のように見え、信頼性の高い配信が必要です。
14203 次
2 に答える
12
私たちが言ったように、それActiveMQ
はより少し重いですZeroMQ
が、それは埋め込まれたプロセスとして本当にうまく機能します。ここでは、とを使用した簡単な例を示しSpring
ますActiveMQ
。
キューのテストに使用されるメッセージリスナー:
public class TestMessageListener implements MessageListener {
private static final Logger logger = LoggerFactory.getLogger(TestMessageListener.class);
@Override
public void onMessage(Message message) {
/* Receive the text message */
if (message instanceof TextMessage) {
try {
String text = ((TextMessage) message).getText();
System.out.println("Message reception from the JMS queue : " + text);
} catch (JMSException e) {
logger.error("Error : " + e.getMessage());
}
} else {
/* Handle non text message */
}
}
}
ActiveMQ
コンテキスト構成:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jmsQueueConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://localhost:61617</value>
</property>
</bean>
<bean id="pooledJmsQueueConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<constructor-arg ref="jmsQueueConnectionFactory" />
</bean>
<bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="messageQueue" />
</bean>
<bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<constructor-arg ref="pooledJmsQueueConnectionFactory" />
<property name="pubSubDomain" value="false"/>
</bean>
<bean id="testMessageListener" class="com.example.jms.TestMessageListener" />
<bean id="messageQueuelistenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="pooledJmsQueueConnectionFactory" />
<property name="destination" ref="QueueDestination" />
<property name="messageListener" ref="testMessageListener" />
<property name="concurrentConsumers" value="5" />
<property name="acceptMessagesWhileStopping" value="false" />
<property name="recoveryInterval" value="10000" />
<property name="cacheLevelName" value="CACHE_CONSUMER" />
</bean>
</beans>
JUnit
テスト:
@ContextConfiguration(locations = {"classpath:/activeMQ-context.xml"})
public class SpringActiveMQTest extends AbstractJUnit4SpringContextTests {
@Autowired
private JmsTemplate template;
@Autowired
private ActiveMQDestination destination;
@Test
public void testJMSFactory() {
/* sending a message */
template.convertAndSend(destination, "Hi");
/* receiving a message */
Object msg = template.receive(destination);
if (msg instanceof TextMessage) {
try {
System.out.println(((TextMessage) msg).getText());
} catch (JMSException e) {
System.out.println("Error : " + e.getMessage());
}
}
}
}
に追加する依存関係pom.xml
:
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- ActiveMQ -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.6.0</version>
</dependency>
于 2013-01-16T17:14:05.483 に答える
1
WebSphere MQ クライアントには、マルチキャスト pub/subを実行する機能があります。これにより、キュー マネージャーをバイパスするクライアント間の機能が提供されますが、接続を確立するにはキュー マネージャーが必要です。
于 2013-01-15T17:02:19.793 に答える