org.springframework.messaging.MessageHandlingException Java Examples

The following examples show how to use org.springframework.messaging.MessageHandlingException. 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: PubSubMessageSourceTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Test
public void doReceive_autoAckModeDoesNotNackAutomatically() {

	PubSubMessageSource pubSubMessageSource = new PubSubMessageSource(
			this.mockPubSubSubscriberOperations, "sub1");
	pubSubMessageSource.setMaxFetchSize(1);
	pubSubMessageSource.setPayloadType(String.class);
	pubSubMessageSource.setAckMode(AckMode.AUTO_ACK);
	MessageSourcePollingTemplate poller = new MessageSourcePollingTemplate(pubSubMessageSource);
	assertThatThrownBy(() -> {
		poller.poll((message) -> {
			throw new RuntimeException("Nope.");
		});
	}).isInstanceOf(MessageHandlingException.class).hasMessageContaining("Nope.");

	verify(this.msg1, times(0)).nack();
}
 
Example #2
Source File: ZmqOutboundGateway.java    From spring-integration-zmq with Apache License 2.0 6 votes vote down vote up
protected Object handleRequestMessage(final Message<?> requestMessage) {
	
	if (!running) {
		return null;
	}
	
	Future<Object> response = executorService.submit(new Callable<Object>() {
		public Object call() throws Exception {
			byte[] requestData = requestConverter.convert(requestMessage.getPayload());
			socket.send(requestData);
			byte[] replyData = socket.recv();
			if (replyData == null) {
				socket.close();
				ZmqOutboundGateway.this.connect();
				throw ZmqEndpointUtil.buildMessageHandlingException(requestMessage, socket.base().errno());
			}
			return replyConverter.convert(replyData);
		}
	});
			
	try {
		return response.get();
	} catch (Throwable t) {
		throw new MessageHandlingException(requestMessage, t);
	}
}
 
Example #3
Source File: GpfdistMessageHandler.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Override
protected void doWrite(Message<?> message) throws Exception {
	Object payload = message.getPayload();
	if (payload instanceof String) {
		String data = (String)payload;
		if (delimiter != null) {
			processor.onNext(Buffer.wrap(data+delimiter));
		} else {
			processor.onNext(Buffer.wrap(data));
		}
		if (meter != null) {
			if ((meterCount++ % rateInterval) == 0) {
				meter.mark(rateInterval);
				log.info("METER: 1 minute rate = " + meter.getOneMinuteRate() + " mean rate = " + meter.getMeanRate());
			}
		}
	} else {
		throw new MessageHandlingException(message, "message not a String");
	}
}
 
Example #4
Source File: PubSubMessageSourceTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Test
public void doReceive_autoModeNacksAutomatically() {

	PubSubMessageSource pubSubMessageSource = new PubSubMessageSource(
			this.mockPubSubSubscriberOperations, "sub1");
	pubSubMessageSource.setMaxFetchSize(1);
	pubSubMessageSource.setPayloadType(String.class);
	pubSubMessageSource.setAckMode(AckMode.AUTO);
	MessageSourcePollingTemplate poller = new MessageSourcePollingTemplate(pubSubMessageSource);
	assertThatThrownBy(() -> {
		poller.poll((message) -> {
			throw new RuntimeException("Nope.");
		});
	}).isInstanceOf(MessageHandlingException.class).hasMessageContaining("Nope.");

	verify(this.msg1).nack();
}
 
Example #5
Source File: ZmqEndpointUtil.java    From spring-integration-zmq with Apache License 2.0 5 votes vote down vote up
public static MessageHandlingException buildMessageHandlingException(Message<?> failedMessage, int errno)  {
	if (errno == ZError.ETERM) {
		return new MessageHandlingException(failedMessage, "ZMQ Context has been terminated");
	} else if (errno == ZError.EAGAIN) {
		return new MessageHandlingException(failedMessage, "ZMQ socket timeout out while attempting to send or receive data over zmq socket");
	} else {
		return new MessageHandlingException(failedMessage, "Unknown error while attempting to send or receive data over zmq socket");
	}
}
 
Example #6
Source File: ZmqLazyPirateGateway.java    From spring-integration-zmq with Apache License 2.0 5 votes vote down vote up
protected Object handleRequestMessage(final Message<?> requestMessage) {
	if (!running) {
		return null;
	}
	
	Future<Object> response = executorService.submit(new Callable<Object>() {
		public Object call() throws Exception {
			byte[] requestData = requestConverter.convert(requestMessage.getPayload());
			int retriesLeft = retryCount;
			while (!Thread.currentThread().isInterrupted()) {
				socket.send(requestData);
				PollItem items[] = { new PollItem(socket, Poller.POLLIN) };
				int rc = ZMQ.poll(items, socketReceiveTimeout);
				if (rc == -1) {
					break;
				}
				if (items[0].isReadable()) {
					byte[] reply = socket.recv();
					return replyConverter.convert(reply);
				} else if (--retriesLeft == 0) {
					break;
				} else {
					ZmqLazyPirateGateway.this.connect();
				}
			}
			ZmqLazyPirateGateway.this.connect();
			return null;
		}
	});
			
	try {
		return response.get();
	} catch (Throwable t) {
		throw new MessageHandlingException(requestMessage, t);
	}
}
 
Example #7
Source File: DefaultPollableMessageSource.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
private void doHandleMessage(MessageHandler handler, Message<?> message) {
	try {
		handler.handleMessage(message);
	}
	catch (Throwable t) { // NOSONAR
		throw new MessageHandlingException(message, t);
	}
}
 
Example #8
Source File: DefaultPollableMessageSource.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
private void requeueOrNack(Message<?> message, AcknowledgmentCallback ackCallback, MessagingException e) {
	if (!ackCallback.isAcknowledged() && shouldRequeue(e)) {
		AckUtils.requeue(ackCallback);
	}
	else {
		AckUtils.autoNack(ackCallback);
		if (e.getFailedMessage().equals(message)) {
			throw e;
		}
		throw new MessageHandlingException(message, e);
	}
}
 
Example #9
Source File: AbstractGpfdistMessageHandler.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Override
protected final void handleMessageInternal(Message<?> message) throws Exception {
	try {
		doWrite(message);
	}
	catch (Exception e) {
		throw new MessageHandlingException(message,
				"failed to write Message payload to GPDB/HAWQ", e);
	}
}
 
Example #10
Source File: LinearRegressionTensorflowProcessorIntegrationTests.java    From tensorflow-spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void testEvaluationIncorrectTupleInput() {
	Tuple incompleteInputTuple = TupleBuilder.tuple()
			//	missing data type
			.put(TF_SHAPE, new long[0])
			.put(TF_VALUE, new byte[0])
			.build();
	testEvaluation(incompleteInputTuple);
}
 
Example #11
Source File: HeaderMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleMissingValue(String headerName, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing header '" + headerName +
			"' for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #12
Source File: HeaderMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String headerName, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing header '" + headerName +
			"' for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #13
Source File: DelayedRequeueExceptionStrategy.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean isMessageException(final Throwable cause) {
    return cause instanceof InvalidTargetAddressException || cause instanceof MessageConversionException
            || cause instanceof MessageHandlingException;
}
 
Example #14
Source File: DestinationVariableMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String name, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing path template variable '" + name + "' " +
			"for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #15
Source File: TaskLauncherLocalSinkIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void sendBadRequest() throws IOException {
	TaskLaunchRequest request = new TaskLaunchRequest("maven://foo", null, null, null);
	sink.input().send(new GenericMessage<>(request));
}
 
Example #16
Source File: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testPolledConsumerWithDlq() throws Exception {
	KafkaTestBinder binder = getBinder();
	PollableSource<MessageHandler> inboundBindTarget = new DefaultPollableMessageSource(
			this.messageConverter);
	ExtendedConsumerProperties<KafkaConsumerProperties> properties = createConsumerProperties();
	properties.getExtension().setPollTimeout(1);
	properties.setMaxAttempts(2);
	properties.setBackOffInitialInterval(0);
	properties.getExtension().setEnableDlq(true);
	Map<String, Object> producerProps = KafkaTestUtils
			.producerProps(embeddedKafka.getEmbeddedKafka());
	Binding<PollableSource<MessageHandler>> binding = binder.bindPollableConsumer(
			"pollableDlq", "group-pcWithDlq", inboundBindTarget, properties);
	KafkaTemplate template = new KafkaTemplate(
			new DefaultKafkaProducerFactory<>(producerProps));
	template.send("pollableDlq", "testPollableDLQ");
	try {
		int n = 0;
		while (n++ < 100) {
			inboundBindTarget.poll(m -> {
				throw new RuntimeException("test DLQ");
			});
			Thread.sleep(100);
		}
	}
	catch (MessageHandlingException e) {
		assertThat(e.getCause().getMessage()).isEqualTo("test DLQ");
	}
	Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("dlq", "false",
			embeddedKafka.getEmbeddedKafka());
	consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
	ConsumerFactory cf = new DefaultKafkaConsumerFactory<>(consumerProps);
	Consumer consumer = cf.createConsumer();
	embeddedKafka.getEmbeddedKafka().consumeFromAnEmbeddedTopic(consumer,
			"error.pollableDlq.group-pcWithDlq");
	ConsumerRecord deadLetter = KafkaTestUtils.getSingleRecord(consumer,
			"error.pollableDlq.group-pcWithDlq");
	assertThat(deadLetter).isNotNull();
	assertThat(deadLetter.value()).isEqualTo("testPollableDLQ");
	binding.unbind();
	consumer.close();
}
 
Example #17
Source File: DestinationVariableMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() throws Exception {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	this.resolver.resolveArgument(this.paramAnnotated, message);
}
 
Example #18
Source File: HeaderMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() throws Exception {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	this.resolver.resolveArgument(this.paramRequired, message);
}
 
Example #19
Source File: HeaderMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() throws Exception {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	this.resolver.resolveArgument(this.resolvable.annot(headerPlain()).arg(), message);
}
 
Example #20
Source File: DestinationVariableMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleMissingValue(String name, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing path template variable '" + name +
			"' for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #21
Source File: DestinationVariableMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String name, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing path template variable '" + name + "' " +
			"for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #22
Source File: HeaderMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String headerName, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing header '" + headerName +
			"' for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #23
Source File: PubSubMessageHandler.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleMessageInternal(Message<?> message) {
	Object payload = message.getPayload();
	String topic =
			message.getHeaders().containsKey(GcpPubSubHeaders.TOPIC)
					? message.getHeaders().get(GcpPubSubHeaders.TOPIC, String.class)
					: this.topicExpression.getValue(this.evaluationContext, message, String.class);

	ListenableFuture<String> pubsubFuture;

	Map<String, String> headers = new HashMap<>();
	this.headerMapper.fromHeaders(message.getHeaders(), headers);

	pubsubFuture = this.pubSubPublisherOperations.publish(topic, payload, headers);

	if (this.publishCallback != null) {
		pubsubFuture.addCallback(this.publishCallback);
	}

	if (this.sync) {
		Long timeout = this.publishTimeoutExpression.getValue(this.evaluationContext, message, Long.class);
		try {
			if (timeout == null || timeout < 0) {
				pubsubFuture.get();
			}
			else {
				pubsubFuture.get(timeout, TimeUnit.MILLISECONDS);
			}
		}
		catch (InterruptedException ie) {
			Thread.currentThread().interrupt();
			throw new MessageHandlingException(message, ie);
		}
		catch (ExecutionException ee) {
			throw new MessageHandlingException(message, ee.getCause());
		}
		catch (TimeoutException te) {
			throw new MessageTimeoutException(message, "Timeout waiting for response from Pub/Sub publisher", te);
		}
	}
}
 
Example #24
Source File: DestinationVariableMethodArgumentResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() throws Exception {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	this.resolver.resolveArgument(this.paramAnnotated, message);
}
 
Example #25
Source File: HeaderMethodArgumentResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() throws Exception {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	this.resolver.resolveArgument(this.paramRequired, message);
}
 
Example #26
Source File: HeaderMethodArgumentResolver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String headerName, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing header '" + headerName +
			"' for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #27
Source File: DestinationVariableMethodArgumentResolver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String name, MethodParameter parameter, Message<?> message) {
	throw new MessageHandlingException(message, "Missing path template variable '" + name +
			"' for method parameter type [" + parameter.getParameterType() + "]");
}
 
Example #28
Source File: DestinationVariableMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message);
}
 
Example #29
Source File: HeaderMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	resolveArgument(this.resolvable.annot(headerPlain()).arg(), message);
}
 
Example #30
Source File: DestinationVariableMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void resolveArgumentNotFound() throws Exception {
	Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
	this.resolver.resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message);
}