我的做法,如果是用数组,集合,对象的话就做出json传递,传过去,如果是数组,集合就使用jsonutil工具,变成list,对象的话就转回对象;
数据简单,我就直接 用textMessage 传
如果数据复杂
就用session.createMapMessage();
生产
@Overridepublic JKResult delContractById(final String id) {contractProductService.deleteProductByContractId(id);contractDao.delContractById(id);jmsTemplate.send(deleDestination, new MessageCreator() {@Overridepublic Message createMessage(Session session) throws JMSException {MapMessage map = session.createMapMessage();String json = JsonUtils.objectToJson(id);map.setString("id", json);return map;}});return JKResult.ok();}
消费
try {
if(mapMessage.getString("ids") !=null||!"".equals(mapMessage.getString("ids"))){
String ids = (String) mapMessage.getObject("ids");
List<String> list = JsonUtils.jsonToList(ids, String.class);
for (String id : list) {
Thread.sleep(1000);
solrServer.deleteById(id);
solrServer.commit();
}
}