我现在使用的是: 春季4.0.0.RELEASE和spring-rabbit 1.4.4.RELEASE
我的代码将处理消息。消息队列不会消失,所以。已经在循环过程中。
弹簧rabbitmq.xml
<bean id="callBackTaskMessageListener" class="com.ghca.easyview.server.api.rabbitmq.worker.CallBackTaskMessageListener">
<property name="rabbitTemplate" ref="rabbitTemplate"/>
</bean>
<rabbit:listener-container connection-factory="connectionFactory" prefetch="1" concurrency="30">
<rabbit:listener queue-names="${backFromTask}" ref="callBackTaskMessageListener"/>
</rabbit:listener-container>
CallBackTaskMessageListener.java
public class CallBackTaskMessageListener implements MessageListener {
private static MessageConverter messageConverter = new SimpleMessageConverter();
private RabbitTemplate rabbitTemplate;
public RabbitTemplate getRabbitTemplate() {
return rabbitTemplate;
}
public void setRabbitTemplate(RabbitTemplate rabbitTemplate) {
this.rabbitTemplate = rabbitTemplate;
}
@Override
public void onMessage(Message requestMessage) {
String message = null;
AbstractCallBack callBackObj = null;
try {
message = new String(requestMessage.getBody(), "utf-8");
if (StringUtils.isBlank(message)) {
throw new CallBackDataException("not null or ''.");
}
JSONObject callBackData = new JSONObject();
JSONObject jsonObject = JSON.parseObject(message);
LogUtils.logInfo("current callBack Data is : "+ jsonObject.toJSONString());
String code = jsonObject.getString("code");
if (StringUtils.isNotBlank(code)) {
JSONObject data = jsonObject.getJSONObject("data");
callBackData.put("data", data);
}
callBackData.put("code", code);
callBackData.put("message", jsonObject.get("message"));
String callBackIdentify = jsonObject.getString("moduleName");
String[] classIndetifyAndMethodName = callBackIdentify.split("&");
callBackObj = CallBackFactory.createCallBack(CallBack.class.getSimpleName());
Method callMethod = callBackObj.getClass().getMethod("call", String.class,String.class,String.class);
callMethod.invoke(callBackObj, callBackData.toJSONString(),classIndetifyAndMethodName[0],classIndetifyAndMethodName[1]);
} catch (Exception e) {
LogUtils.logError(callBackObj.getClass().getName() + "->error.",e);
} finally {
//rabbitTemplate.getMessageConverter().
}
}
}
如何解决不要让他处理专栏新闻。如何处理消息的正确回复?感谢。