我有一个Websphere MQ和一个java app receiveng消息。如果在我的应用程序中抛出任何异常,我想制作重新传送系统。我使用的是Spring事务管理器,但问题是如果消息在我的应用程序中导致异常,则应用程序正在尝试重新发送相同的消息。如果有一些(2,3等)不成功的重新传递尝试,我可以在队列的末尾添加一条损坏的消息吗?
这是我的弹簧配置:
<bean id="mqMessageListener" class="ru.mos.notification.controller.MQNotificationListener">
<property name="mqwsUrl" value="${mqws.url}" />
<property name="mqwsSoapAction" value="${mqws.soapAction}" />
<property name="mqwsSoapStart" value="${mqws.soapStart}" />
<property name="mqwsSoapEnd" value="${mqws.soapEnd}" />
</bean>
<bean id="mqQueueConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="hostName" value="${mq.hostName}" />
<property name="port" value="${mq.port}" />
<property name="queueManager" value="${mq.queueManager}" />
<property name="transportType" value="1" />
<property name="channel" value="${mq.channel}" />
</bean>
<bean id="jmsConnectionFactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="mqQueueConnectionFactory" />
<property name="username" value="${mq.username}" />
<property name="password" value="${mq.password}" />
</bean>
<bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destinationName" value="${mq.destinationName}" />
<property name="destinationResolver">
<bean
class="org.springframework.jms.support.destination.DynamicDestinationResolver" />
</property>
<property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" />
<property name="sessionTransacted" value="true" />
<property name="messageListener" ref="mqMessageListener" />
<property name="transactionManager" ref="transactionManager"/>
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
这里是onMessage方法的代码:
public void onMessage(Message mess) {
try {
if (mess instanceof TextMessage) {
String m = ((TextMessage) mess).getText();
logger.info("MQNotificationListener.onMessage TextMessage=" + m);
Properties prop = new Properties();
prop.setProperty("SOAPAction", mqwsSoapAction);
HTTPSend.sendHTTP(mqwsUrl, mqwsSoapStart + m + mqwsSoapEnd,
"UTF-8", prop);
String response = HTTPSend.sendHTTP(mqwsUrl, mqwsSoapStart + m
+ mqwsSoapEnd, "UTF-8", prop);
checkResponse(response);
} else if (mess instanceof BytesMessage) {
/*
* byte[] body = new byte[(int) ((BytesMessage)
* mess).getBodyLength()]; ((BytesMessage)
* mess).readBytes(body);
*
* String enc = Utils.getProperty(Utils.FP_MIGRATION,
* "mqrec.encoding");
*
* text = new String(body, enc);
*/
logger.info("MQMessageListener.onMessage BytesMessage");
} else {
logger.info("MQMessageListener.onMessage other");
}
} catch (Exception e) {
logger.error(
"MQMessageListener.onMessage Exception: " + e.getMessage(),
e);
throw JmsUtils.convertJmsAccessException(new JMSException(null));
}
}
答案 0 :(得分:0)
队列以FIFO为基础,先进先出。
所以有两个选项
这两个选项都要求消费者与制作人合作。