[英]WSO2 ESB + activeMQ
I'm new in wso2 esb and jms. 我是wso2 esb和jms的新手。 I send some messages from soapUI to wso2 esb.
我从soapUI发送一些消息到wso2 esb。 In my wso sequence a processed message goes to the jms.
在我的wso序列中,处理过的消息进入jms。 Is there a possibility to set "time to live" of this message from wso2 esb?
是否有可能从wso2 esb中设置此消息的“生存时间”? Or some other ways?
还是其他一些方法?
In AMQ I added this: 在AMQ我添加了这个:
<policyEntry queue="myQueue">
<deadLetterStrategy>
<individualDeadLetterStrategy
queuePrefix="DLQ." useQueueForQueueMessages="true" />
</deadLetterStrategy>
Something like <property name="JMSExpiration" value="today+hour_long_value" scope="transport" type="STRING"></property>
in sequence have no effect. 类似
<property name="JMSExpiration" value="today+hour_long_value" scope="transport" type="STRING"></property>
的顺序无效。
If you are using JMS Message Store you can just set property JMS_PROD_TIME_TO_LIVE. 如果您使用的是JMS消息存储库,则只需设置属性JMS_PROD_TIME_TO_LIVE即可。
<property name="JMS_PROD_TIME_TO_LIVE" value="15000" />
<store messageStore="my_jms_message_store" />
Tested with WSO2 ESB 4.9.0 (with synapse version 2.1.3-wso2v11) 使用WSO2 ESB 4.9.0(带有synapse版本2.1.3-wso2v11)进行测试
You can find more information in JmsProducer code 您可以在JmsProducer代码中找到更多信息
Same way you can set for example message priority (property JMS_PROD_PRIORITY). 您可以设置相同的消息优先级(属性JMS_PROD_PRIORITY)。
The only workable way, I found out, is to create own Mediator, which will set the time-to-live of a message and send it to the queue. 我发现,唯一可行的方法是创建自己的Mediator,它将设置消息的生存时间并将其发送到队列。 The queue name is preset in a sequence, then called mediator:
队列名称按顺序预设,然后称为中介:
<property xmlns="http://ws.apache.org/ns/synapse" name="qname" value="your_queue_name" scope="default" type="STRING"></property>
<class xmlns="http://ws.apache.org/ns/synapse" name="com.example.JMSMessageTimeToLiveMediator"></class>
A mediator class: 调解员类:
public class JMSMessageTimeToLiveMediator extends AbstractMediator implements
ManagedLifecycle {
private static String CON_FACTORY_NAME = "QueueConnectionFactory";
private static String DEF_PROP_QNAME = "qname";
private static long TIME_TO_LIVE = 60000;
private static QueueConnectionFactory cf;
public boolean mediate(MessageContext context) {
Connection connection = null;
Session session = null;
try {
connection = cf.createQueueConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
String queueName = (String) context.getProperty(DEF_PROP_QNAME);
Destination destination = session.createQueue(queueName);
MessageProducer producer = session.createProducer(destination);
producer.setTimeToLive(TIME_TO_LIVE);
TextMessage message = session.createTextMessage(context
.getEnvelope().toString());
producer.send(message);
} catch (JMSException e) {
log.error("ProduceJMS ERROR: " + e.getClass() + " "
+ e.getMessage());
} catch (Exception e) {
log.error("ProduceJMS ERROR: " + e.getClass() + " "
+ e.getMessage());
} finally {
try {
session.close();
connection.close();
} catch (JMSException e) {
log.error("ProduceJMS ERROR: " + e.getMessage());
}
}
return true;
}
public void init(SynapseEnvironment emvironment) {
Hashtable<String, Object> environment = new Hashtable<String, Object>();
environment.put("java.naming.factory.initial",
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
log.debug("ProduceJMS INIT");
try {
InitialContext ic = new InitialContext(environment);
cf = (QueueConnectionFactory) ic.lookup(CON_FACTORY_NAME);
} catch (NamingException e) {
log.error("ProduceJMS INIT ERROR: " + e.getMessage());
}
}
public void destroy() {
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.