本文整理汇总了Java中org.springframework.amqp.rabbit.core.RabbitTemplate.setReplyTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java RabbitTemplate.setReplyTimeout方法的具体用法?Java RabbitTemplate.setReplyTimeout怎么用?Java RabbitTemplate.setReplyTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.amqp.rabbit.core.RabbitTemplate
的用法示例。
在下文中一共展示了RabbitTemplate.setReplyTimeout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.springframework.amqp.rabbit.core.RabbitTemplate; //导入方法依赖的package包/类
/**
* @Title: call
* @Description: call类型,点对点发送接收消息
* @param topicRoutingKey
* @param serverName
* @param bodyMsg
* @param outTimeMillis
* @throws Exception 设定文件
* @return Map<String,Object> 返回类型
*/
public Map<String,Object> call(String topicRoutingKey,String serverName,Map<String,Object> bodyMsg,int outTimeMillis) throws Exception{
Map<String,Object> sendMsg = new HashMap<String,Object>();
sendMsg.put("mqkey",topicRoutingKey+"."+serverName);
sendMsg.put("mqtype","call");
sendMsg.put("mqbody",bodyMsg==null?new HashMap<String,Object>():bodyMsg);
String topicMessage = JSON.toJSONString(sendMsg, JsonFilter.filter);
Message message=new Message(topicMessage.getBytes("UTF-8"),new MessageProperties());
RabbitTemplate directTemplate =new RabbitTemplate();
directTemplate.setConnectionFactory(connectionFactory);
directTemplate.setExchange(PropertyLoader.MQ_EXCHANGE);
directTemplate.setReplyTimeout(outTimeMillis);
Message reply=directTemplate.sendAndReceive(topicRoutingKey,message);
if(reply==null){
throw new Exception("waitting rabbitmq response timeout");
}
String body=new String(reply.getBody(),"UTF-8");
Map<String,Object> reqMsgMap =JSON.parseObject(body,new TypeReference<Map<String, Object>>(){});
LOG.info("back :"+reqMsgMap);
reqMsgMap =JSON.parseObject(reqMsgMap.get("mqbody").toString(),new TypeReference<Map<String, Object>>(){});
return reqMsgMap;
}
示例2: createDmfClient
import org.springframework.amqp.rabbit.core.RabbitTemplate; //导入方法依赖的package包/类
private RabbitTemplate createDmfClient() {
final RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setMessageConverter(new Jackson2JsonMessageConverter());
template.setReceiveTimeout(TimeUnit.SECONDS.toMillis(3));
template.setReplyTimeout(TimeUnit.SECONDS.toMillis(3));
template.setExchange(getExchange());
return template;
}
示例3: rabbitTemplateForTest
import org.springframework.amqp.rabbit.core.RabbitTemplate; //导入方法依赖的package包/类
@Bean
@Primary
public RabbitTemplate rabbitTemplateForTest(ConnectionFactory connectionFactory) {
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
rabbitTemplate.setReplyTimeout(TimeUnit.SECONDS.toMillis(3));
rabbitTemplate.setReceiveTimeout(TimeUnit.SECONDS.toMillis(3));
return rabbitTemplate;
}
示例4: internalExecute
import org.springframework.amqp.rabbit.core.RabbitTemplate; //导入方法依赖的package包/类
private void internalExecute(InsuranceTask task) throws JsonProcessingException {
Assert.notNull(task.getData(), "Missing task data");
String routingKey = task.getDestinationQueue();
Object data = task.getData();
String message = mapper.writeValueAsString(data);
try {
log.info("Sending message to {}", routingKey);
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setReplyTimeout(5000);
rabbitTemplate.setReceiveTimeout(5000);
rabbitTemplate.setQueue(routingKey);
// TODO
boolean sync = false;
if (sync) {
Object response = rabbitTemplate.convertSendAndReceive(routingKey, message);
log.info("Received message from {}: {}", routingKey, response);
}
else {
rabbitTemplate.convertAndSend(routingKey, message);
try {
Thread.sleep(5000);
}
catch (InterruptedException e) {
}
}
}
catch (RuntimeException ex) {
log.error("Task execution error using routingKey {}", routingKey);
throw new InsuranceException("Task execution error", ex);
}
}
示例5: fixedReplyQRabbitTemplate
import org.springframework.amqp.rabbit.core.RabbitTemplate; //导入方法依赖的package包/类
@Bean
RabbitTemplate fixedReplyQRabbitTemplate(Exchange exchange, @Qualifier(REPLY_Q) Queue replyQueue, ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setExchange(exchange.getName());
template.setRoutingKey(this.routingKey);
template.setReplyTimeout(-1); // this means that it should wait forever for a reply. TODO is this too dangerous ?
template.setReplyQueue(replyQueue);
return template;
}
示例6: init
import org.springframework.amqp.rabbit.core.RabbitTemplate; //导入方法依赖的package包/类
/**
*
*/
private static void init() {
connectionFactory = newConnectionFactory();
rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(new ElfMessageConverter());
rabbitTemplate.setRoutingKey(CLIENT_SYNC_RCP_Q);
rabbitTemplate.setReplyTimeout(-1);
rabbitAdmin = new RabbitAdmin(connectionFactory);
}