[英]WSO2 ESB + activeMQ
我是wso2 esb和jms的新手。 我從soapUI發送一些消息到wso2 esb。 在我的wso序列中,處理過的消息進入jms。 是否有可能從wso2 esb中設置此消息的“生存時間”? 還是其他一些方法?
在AMQ我添加了這個:
<policyEntry queue="myQueue">
<deadLetterStrategy>
<individualDeadLetterStrategy
queuePrefix="DLQ." useQueueForQueueMessages="true" />
</deadLetterStrategy>
類似<property name="JMSExpiration" value="today+hour_long_value" scope="transport" type="STRING"></property>
的順序無效。
如果您使用的是JMS消息存儲庫,則只需設置屬性JMS_PROD_TIME_TO_LIVE即可。
<property name="JMS_PROD_TIME_TO_LIVE" value="15000" />
<store messageStore="my_jms_message_store" />
使用WSO2 ESB 4.9.0(帶有synapse版本2.1.3-wso2v11)進行測試
您可以在JmsProducer代碼中找到更多信息
您可以設置相同的消息優先級(屬性JMS_PROD_PRIORITY)。
我發現,唯一可行的方法是創建自己的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>
調解員類:
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.