public void send() { String context = "hi, i am message all"; System.out.println("Sender : " + context); this.rabbitTemplate.convertAndSend("topicExchange", "topic.1", context); }
@Override @SuppressWarnings("unchecked") public T read() { if (itemType != null && itemType.isAssignableFrom(Message.class)) { return (T) amqpTemplate.receive(); } Object result = amqpTemplate.receiveAndConvert(); if (itemType != null && result != null) { Assert.state(itemType.isAssignableFrom(result.getClass()), "Received message payload of wrong type: expected [" + itemType + "]"); } return (T) result; }
@Test public void testAmqpInboundGatewayFlow() { assertNotNull(this.amqpInboundGatewayContainer); assertSame(this.amqpTemplate, TestUtils.getPropertyValue(this.amqpInboundGateway, "amqpTemplate")); Object result = this.amqpTemplate.convertSendAndReceive(this.amqpQueue.getName(), "world"); assertEquals("HELLO WORLD", result); this.amqpInboundGateway.stop(); //INTEXT-209 this.amqpInboundGateway.start(); this.amqpTemplate.convertAndSend(this.amqpQueue.getName(), "world"); ((RabbitTemplate) this.amqpTemplate).setReceiveTimeout(10000); result = this.amqpTemplate.receiveAndConvert("defaultReplyTo"); assertEquals("HELLO WORLD", result); }
@Override protected boolean doSend(Message<?> message, long timeout) { if (this.extractPayload) { this.amqpTemplate.send(getExchangeName(), getRoutingKey(), MappingUtils.mapMessage(message, this.rabbitTemplate.getMessageConverter(), this.outboundHeaderMapper, this.defaultDeliveryMode, this.headersMappedLast)); } else { this.amqpTemplate.convertAndSend(getExchangeName(), getRoutingKey(), message); } return true; }
String routingKey = this.errorRoutingKey != null ? this.errorRoutingKey : this.prefixedOriginalRoutingKey(message); this.errorTemplate.send(this.errorExchangeName, routingKey, message); if (this.logger.isWarnEnabled()) { this.logger.warn("Republishing failed message to exchange '" + this.errorExchangeName this.errorTemplate.send(routingKey, message); if (this.logger.isWarnEnabled()) { this.logger.warn("Republishing failed message to the template's default exchange with routing key "
@Test public void testNoItemType() { final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class); when(amqpTemplate.receiveAndConvert()).thenReturn("foo"); final AmqpItemReader<String> amqpItemReader = new AmqpItemReader<>(amqpTemplate); assertEquals("foo", amqpItemReader.read()); }
if(exchange.getPattern().isOutCapable()) { LOG.debug("Synchronous send and request for exchange {}", exchange.getExchangeId()); Message amqpResponse = endpoint.getAmqpTemplate().sendAndReceive(exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter)); SpringAMQPMessage camelResponse = SpringAMQPMessage.fromAMQPMessage(msgConverter, amqpResponse); endpoint.getAmqpTemplate().send(exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter));
public Object sendAndReceive(String route, Object message) { return amqpTemplate.convertSendAndReceive(route, message); } }
@Test public void testAmqpInboundGatewayFlow() throws Exception { Object result = this.amqpTemplate.convertSendAndReceive(this.amqpQueue.getName(), "world"); assertEquals("HELLO WORLD", result); this.amqpInboundGateway.stop(); //INTEXT-209 this.amqpInboundGateway.start(); this.amqpTemplate.convertAndSend(this.amqpQueue.getName(), "world"); ((RabbitTemplate) this.amqpTemplate).setReceiveTimeout(10000); result = this.amqpTemplate.receiveAndConvert("defaultReplyTo"); assertEquals("HELLO WORLD", result); assertSame(this.amqpTemplate, TestUtils.getPropertyValue(this.amqpInboundGateway, "amqpTemplate")); }
@Override protected boolean doSend(Message<?> message, long timeout) { if (this.extractPayload) { this.amqpTemplate.send(getExchangeName(), getRoutingKey(), MappingUtils.mapMessage(message, this.rabbitTemplate.getMessageConverter(), this.outboundHeaderMapper, this.defaultDeliveryMode, this.headersMappedLast)); } else { this.amqpTemplate.convertAndSend(getExchangeName(), getRoutingKey(), message); } return true; }
String routingKey = this.errorRoutingKey != null ? this.errorRoutingKey : this.prefixedOriginalRoutingKey(message); this.errorTemplate.send(this.errorExchangeName, routingKey, message); if (this.logger.isWarnEnabled()) { this.logger.warn("Republishing failed message to exchange '" + this.errorExchangeName this.errorTemplate.send(routingKey, message); if (this.logger.isWarnEnabled()) { this.logger.warn("Republishing failed message to the template's default exchange with routing key "
@Test public void testTypeMismatch() { final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class); when(amqpTemplate.receiveAndConvert()).thenReturn("foo"); final AmqpItemReader<Integer> amqpItemReader = new AmqpItemReader<>(amqpTemplate); amqpItemReader.setItemType(Integer.class); try { amqpItemReader.read(); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains("wrong type")); } }
if(exchange.getPattern().isOutCapable()) { LOG.debug("Synchronous send and request for exchange {}", exchange.getExchangeId()); Message amqpResponse = endpoint.getAmqpTemplate().sendAndReceive(exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter)); SpringAMQPMessage camelResponse = SpringAMQPMessage.fromAMQPMessage(msgConverter, amqpResponse); endpoint.getAmqpTemplate().send(exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter));
@Override public Object invoke(MethodInvocation invocation) throws Throwable { RemoteInvocation remoteInvocation = getRemoteInvocationFactory().createRemoteInvocation(invocation); Object rawResult; if (getRoutingKey() == null) { // Use the template's default routing key rawResult = this.amqpTemplate.convertSendAndReceive(remoteInvocation); } else { rawResult = this.amqpTemplate.convertSendAndReceive(this.routingKey, remoteInvocation); } if (rawResult == null) { throw new RemoteProxyFailureException("No reply received from '" + remoteInvocation.getMethodName() + "' with arguments '" + Arrays.asList(remoteInvocation.getArguments()) + // NOSONAR (null) "' - perhaps a timeout in the template?", null); } else if (!(rawResult instanceof RemoteInvocationResult)) { throw new RemoteProxyFailureException("Expected a result of type " + RemoteInvocationResult.class.getCanonicalName() + " but found " + rawResult.getClass().getCanonicalName(), null); // NOSONAR (null) } RemoteInvocationResult result = (RemoteInvocationResult) rawResult; return result.recreate(); }
public void send() { String context = "hi, fanout msg "; System.out.println("Sender : " + context); this.rabbitTemplate.convertAndSend("fanoutExchange","", context); }
@Test public void shouldPublishWithRoutingKeyPrefixedWithErrorWhenExchangeIsNotSet() { recoverer = new RepublishMessageRecoverer(amqpTemplate); recoverer.recover(message, cause); verify(amqpTemplate).send("error.some.key", message); }
@Test public void testNonMessageItemType() { final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class); when(amqpTemplate.receiveAndConvert()).thenReturn("foo"); final AmqpItemReader<String> amqpItemReader = new AmqpItemReader<>(amqpTemplate); amqpItemReader.setItemType(String.class); assertEquals("foo", amqpItemReader.read()); }
@Override @SuppressWarnings("unchecked") public T read() { if (itemType != null && itemType.isAssignableFrom(Message.class)) { return (T) amqpTemplate.receive(); } Object result = amqpTemplate.receiveAndConvert(); if (itemType != null && result != null) { Assert.state(itemType.isAssignableFrom(result.getClass()), "Received message payload of wrong type: expected [" + itemType + "]"); } return (T) result; }
public void send(int i) { String context = "spirng boot neo queue"+" ****** "+i; System.out.println("Sender1 : " + context); this.rabbitTemplate.convertAndSend("neo", context); }
@Override public void recover(final Message message, final Throwable cause) { Map<String, Object> headers = message.getMessageProperties().getHeaders(); headers.put("x-exception-stacktrace", ExceptionUtils.getFullStackTrace(cause)); headers.put("x-exception-message", ExceptionUtils.getMessage(cause)); headers.put("x-exception-root-cause-message", ExceptionUtils.getRootCauseMessage(cause)); headers.put("x-original-exchange", message.getMessageProperties().getReceivedExchange()); headers.put("x-original-routingKey", message.getMessageProperties().getReceivedRoutingKey()); headers.put("x-original-queue", message.getMessageProperties().getConsumerQueue()); headers.put("x-recover-time", new Date().toString()); String deadLetterExchangeName = rabbitmqProperties.getDeadLetterConfig().getDeadLetterExchange().getName(); String deadLetterRoutingKey = rabbitmqProperties.getDeadLetterConfig().createDeadLetterQueueName(message.getMessageProperties().getConsumerQueue()); headers.put("x-dead-letter-exchange", deadLetterExchangeName); headers.put("x-dead-letter-queue", deadLetterRoutingKey); if(headers.containsKey("correlation-id")) { message.getMessageProperties().setCorrelationIdString((String) headers.get("correlation-id")); } headers.putAll(loadAdditionalHeaders(message, cause)); for (MessageExceptionHandler messageExceptionHandler : messageExceptionHandlers) { try { messageExceptionHandler.handle(message, cause); } catch (Exception e) { // To catch any exception in the MessageExceptionHandler to avoid the interruption in other MessageExceptionHandlers log.error("Exception occurred while processing '{}' message exception handler.", messageExceptionHandler, e); } } this.errorTemplate.send(deadLetterExchangeName, deadLetterRoutingKey, message); log.warn("Republishing failed message to exchange '{}', routing key '{}', message {{}} , cause {}", deadLetterExchangeName, deadLetterRoutingKey, message, cause); }