org.springframework.messaging.MessagingException Java Examples
The following examples show how to use
org.springframework.messaging.MessagingException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProducerACLApplication.java From rocketmq-spring with Apache License 2.0 | 6 votes |
private void testTransaction() throws MessagingException { String[] tags = new String[]{"TagA", "TagB", "TagC", "TagD", "TagE"}; for (int i = 0; i < 10; i++) { try { Message msg = MessageBuilder.withPayload("Hello RocketMQ " + i). setHeader(RocketMQHeaders.TRANSACTION_ID, "KEY_" + i).build(); SendResult sendResult = rocketMQTemplate.sendMessageInTransaction( springTransTopic + ":" + tags[i % tags.length], msg, null); System.out.printf("------ send Transactional msg body = %s , sendResult=%s %n", msg.getPayload(), sendResult.getSendStatus()); Thread.sleep(10); } catch (Exception e) { e.printStackTrace(); } } }
Example #2
Source File: RocketMQTemplate.java From rocketmq-spring with Apache License 2.0 | 6 votes |
/** * Same to {@link #asyncSend(String, Message, SendCallback)} with send timeout and delay level specified in * addition. * * @param destination formats: `topicName:tags` * @param message {@link org.springframework.messaging.Message} * @param sendCallback {@link SendCallback} * @param timeout send timeout with millis * @param delayLevel level for the delay message */ public void asyncSend(String destination, Message<?> message, SendCallback sendCallback, long timeout, int delayLevel) { if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { log.error("asyncSend failed. destination:{}, message is null ", destination); throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); } try { org.apache.rocketmq.common.message.Message rocketMsg = this.createRocketMqMessage(destination, message); if (delayLevel > 0) { rocketMsg.setDelayTimeLevel(delayLevel); } producer.send(rocketMsg, sendCallback, timeout); } catch (Exception e) { log.info("asyncSend failed. destination:{}, message:{} ", destination, message); throw new MessagingException(e.getMessage(), e); } }
Example #3
Source File: RocketMQTemplate.java From rocketmq-spring with Apache License 2.0 | 6 votes |
/** * Same to {@link #syncSend(String, Message)} with send timeout specified in addition. * * @param destination formats: `topicName:tags` * @param message {@link org.springframework.messaging.Message} * @param timeout send timeout with millis * @param delayLevel level for the delay message * @return {@link SendResult} */ public SendResult syncSend(String destination, Message<?> message, long timeout, int delayLevel) { if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { log.error("syncSend failed. destination:{}, message is null ", destination); throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); } try { long now = System.currentTimeMillis(); org.apache.rocketmq.common.message.Message rocketMsg = this.createRocketMqMessage(destination, message); if (delayLevel > 0) { rocketMsg.setDelayTimeLevel(delayLevel); } SendResult sendResult = producer.send(rocketMsg, timeout); long costTime = System.currentTimeMillis() - now; if (log.isDebugEnabled()) { log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId()); } return sendResult; } catch (Exception e) { log.error("syncSend failed. destination:{}, message:{} ", destination, message); throw new MessagingException(e.getMessage(), e); } }
Example #4
Source File: RecommendationServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int recommendationId = 1; sendCreateRecommendationEvent(productId, recommendationId); assertEquals(1, (long)repository.count().block()); try { sendCreateRecommendationEvent(productId, recommendationId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Recommendation Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, (long)repository.count().block()); }
Example #5
Source File: ProducerApplication.java From rocketmq-spring with Apache License 2.0 | 6 votes |
private void testRocketMQTemplateTransaction() throws MessagingException { String[] tags = new String[] {"TagA", "TagB", "TagC", "TagD", "TagE"}; for (int i = 0; i < 10; i++) { try { Message msg = MessageBuilder.withPayload("rocketMQTemplate transactional message " + i). setHeader(RocketMQHeaders.TRANSACTION_ID, "KEY_" + i).build(); SendResult sendResult = rocketMQTemplate.sendMessageInTransaction( springTransTopic + ":" + tags[i % tags.length], msg, null); System.out.printf("------rocketMQTemplate send Transactional msg body = %s , sendResult=%s %n", msg.getPayload(), sendResult.getSendStatus()); Thread.sleep(10); } catch (Exception e) { e.printStackTrace(); } } }
Example #6
Source File: ReviewServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int reviewId = 1; assertEquals(0, repository.count()); sendCreateReviewEvent(productId, reviewId); assertEquals(1, repository.count()); try { sendCreateReviewEvent(productId, reviewId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Review Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, repository.count()); }
Example #7
Source File: ReviewServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int reviewId = 1; assertEquals(0, repository.count()); sendCreateReviewEvent(productId, reviewId); assertEquals(1, repository.count()); try { sendCreateReviewEvent(productId, reviewId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Review Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, repository.count()); }
Example #8
Source File: ReviewServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int reviewId = 1; assertEquals(0, repository.count()); sendCreateReviewEvent(productId, reviewId); assertEquals(1, repository.count()); try { sendCreateReviewEvent(productId, reviewId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Review Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, repository.count()); }
Example #9
Source File: ReviewServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int reviewId = 1; assertEquals(0, repository.count()); sendCreateReviewEvent(productId, reviewId); assertEquals(1, repository.count()); try { sendCreateReviewEvent(productId, reviewId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Review Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, repository.count()); }
Example #10
Source File: RecommendationServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int recommendationId = 1; sendCreateRecommendationEvent(productId, recommendationId); assertEquals(1, (long)repository.count().block()); try { sendCreateRecommendationEvent(productId, recommendationId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Recommendation Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, (long)repository.count().block()); }
Example #11
Source File: RecommendationServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int recommendationId = 1; sendCreateRecommendationEvent(productId, recommendationId); assertEquals(1, (long)repository.count().block()); try { sendCreateRecommendationEvent(productId, recommendationId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Recommendation Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, (long)repository.count().block()); }
Example #12
Source File: ReviewServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int reviewId = 1; assertEquals(0, repository.count()); sendCreateReviewEvent(productId, reviewId); assertEquals(1, repository.count()); try { sendCreateReviewEvent(productId, reviewId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Review Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, repository.count()); }
Example #13
Source File: ProducerApplication.java From rocketmq-spring with Apache License 2.0 | 6 votes |
private void testExtRocketMQTemplateTransaction() throws MessagingException { for (int i = 0; i < 10; i++) { try { Message msg = MessageBuilder.withPayload("extRocketMQTemplate transactional message " + i). setHeader(RocketMQHeaders.TRANSACTION_ID, "KEY_" + i).build(); SendResult sendResult = extRocketMQTemplate.sendMessageInTransaction( springTransTopic, msg, null); System.out.printf("------ExtRocketMQTemplate send Transactional msg body = %s , sendResult=%s %n", msg.getPayload(), sendResult.getSendStatus()); Thread.sleep(10); } catch (Exception e) { e.printStackTrace(); } } }
Example #14
Source File: RecommendationServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int recommendationId = 1; sendCreateRecommendationEvent(productId, recommendationId); assertEquals(1, (long)repository.count().block()); try { sendCreateRecommendationEvent(productId, recommendationId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Recommendation Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, (long)repository.count().block()); }
Example #15
Source File: ProductServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; assertNull(repository.findByProductId(productId).block()); sendCreateProductEvent(productId); assertNotNull(repository.findByProductId(productId).block()); try { sendCreateProductEvent(productId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: " + productId, iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } }
Example #16
Source File: RocketMQTemplate.java From rocketmq-spring with Apache License 2.0 | 6 votes |
/** * Same to {@link #syncSendOrderly(String, Message, String)} with send timeout specified in addition. * * @param destination formats: `topicName:tags` * @param message {@link org.springframework.messaging.Message} * @param hashKey use this key to select queue. for example: orderId, productId ... * @param timeout send timeout with millis * @return {@link SendResult} */ public SendResult syncSendOrderly(String destination, Message<?> message, String hashKey, long timeout) { if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { log.error("syncSendOrderly failed. destination:{}, message is null ", destination); throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); } try { long now = System.currentTimeMillis(); org.apache.rocketmq.common.message.Message rocketMsg = this.createRocketMqMessage(destination, message); SendResult sendResult = producer.send(rocketMsg, messageQueueSelector, hashKey, timeout); long costTime = System.currentTimeMillis() - now; if (log.isDebugEnabled()) { log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId()); } return sendResult; } catch (Exception e) { log.error("syncSendOrderly failed. destination:{}, message:{} ", destination, message); throw new MessagingException(e.getMessage(), e); } }
Example #17
Source File: ProductServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; assertNull(repository.findByProductId(productId).block()); sendCreateProductEvent(productId); assertNotNull(repository.findByProductId(productId).block()); try { sendCreateProductEvent(productId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: " + productId, iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } }
Example #18
Source File: ProductServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; assertNull(repository.findByProductId(productId).block()); sendCreateProductEvent(productId); assertNotNull(repository.findByProductId(productId).block()); try { sendCreateProductEvent(productId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: " + productId, iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } }
Example #19
Source File: RecommendationServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int recommendationId = 1; sendCreateRecommendationEvent(productId, recommendationId); assertEquals(1, (long)repository.count().block()); try { sendCreateRecommendationEvent(productId, recommendationId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Recommendation Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, (long)repository.count().block()); }
Example #20
Source File: RecommendationServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int recommendationId = 1; sendCreateRecommendationEvent(productId, recommendationId); assertEquals(1, (long)repository.count().block()); try { sendCreateRecommendationEvent(productId, recommendationId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Recommendation Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, (long)repository.count().block()); }
Example #21
Source File: ReviewServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; int reviewId = 1; assertEquals(0, repository.count()); sendCreateReviewEvent(productId, reviewId); assertEquals(1, repository.count()); try { sendCreateReviewEvent(productId, reviewId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: 1, Review Id:1", iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } assertEquals(1, repository.count()); }
Example #22
Source File: ProductServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; assertNull(repository.findByProductId(productId).block()); sendCreateProductEvent(productId); assertNotNull(repository.findByProductId(productId).block()); try { sendCreateProductEvent(productId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: " + productId, iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } }
Example #23
Source File: ProductServiceApplicationTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 6 votes |
@Test public void duplicateError() { int productId = 1; assertNull(repository.findByProductId(productId).block()); sendCreateProductEvent(productId); assertNotNull(repository.findByProductId(productId).block()); try { sendCreateProductEvent(productId); fail("Expected a MessagingException here!"); } catch (MessagingException me) { if (me.getCause() instanceof InvalidInputException) { InvalidInputException iie = (InvalidInputException)me.getCause(); assertEquals("Duplicate key, Product Id: " + productId, iie.getMessage()); } else { fail("Expected a InvalidInputException as the root cause!"); } } }
Example #24
Source File: JmsMessagingTemplate.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public <T> T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass) throws MessagingException { return convertSendAndReceive(destinationName, request, headers, targetClass, null); }
Example #25
Source File: SimpMessagingTemplate.java From java-technology-stack with MIT License | 5 votes |
@Override public void convertAndSendToUser(String user, String destination, Object payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) throws MessagingException { Assert.notNull(user, "User must not be null"); user = StringUtils.replace(user, "/", "%2F"); destination = destination.startsWith("/") ? destination : "/" + destination; super.convertAndSend(this.destinationPrefix + user + destination, payload, headers, postProcessor); }
Example #26
Source File: JmsMessagingTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void convertMessageNotReadableException() throws JMSException { willThrow(MessageNotReadableException.class).given(this.jmsTemplate).receive("myQueue"); this.thrown.expect(MessagingException.class); this.messagingTemplate.receive("myQueue"); }
Example #27
Source File: JmsMessagingTemplate.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException { return convertSendAndReceive(destinationName, request, null, targetClass, requestPostProcessor); }
Example #28
Source File: AbstractMessageChannel.java From spring-analysis-note with MIT License | 5 votes |
@Override public final boolean send(Message<?> message, long timeout) { Assert.notNull(message, "Message must not be null"); Message<?> messageToUse = message; ChannelInterceptorChain chain = new ChannelInterceptorChain(); boolean sent = false; try { messageToUse = chain.applyPreSend(messageToUse, this); if (messageToUse == null) { return false; } sent = sendInternal(messageToUse, timeout); chain.applyPostSend(messageToUse, this, sent); chain.triggerAfterSendCompletion(messageToUse, this, sent, null); return sent; } catch (Exception ex) { chain.triggerAfterSendCompletion(messageToUse, this, sent, ex); if (ex instanceof MessagingException) { throw (MessagingException) ex; } throw new MessageDeliveryException(messageToUse,"Failed to send message to " + this, ex); } catch (Throwable err) { MessageDeliveryException ex2 = new MessageDeliveryException(messageToUse, "Failed to send message to " + this, err); chain.triggerAfterSendCompletion(messageToUse, this, sent, ex2); throw ex2; } }
Example #29
Source File: AbstractMethodMessageHandler.java From spring-analysis-note with MIT License | 5 votes |
@Override public Mono<Void> handleMessage(Message<?> message) throws MessagingException { Match<T> match = getHandlerMethod(message); if (match == null) { // handleNoMatch would have been invoked already return Mono.empty(); } return handleMatch(match.mapping, match.handlerMethod, message); }
Example #30
Source File: JmsMessagingTemplate.java From java-technology-stack with MIT License | 5 votes |
@Override public void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { convertAndSend(defaultDestination, payload, postProcessor); } else { convertAndSend(getRequiredDefaultDestinationName(), payload, postProcessor); } }