view spring-jms-playground/src/main/java/de/comline/jms/receiver/QueueReceiver.java @ 17:a9675808f1dd

Triggern der exception je nach Payload
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 10 Sep 2020 11:18:13 +0200
parents 4217059d40e8
children
line wrap: on
line source

package de.comline.jms.receiver;

import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import de.comline.jms.application.Application;

@Component
public class QueueReceiver {
	private static final Logger LOG = LoggerFactory.getLogger(QueueReceiver.class);

	@JmsListener(destination = "input-queue", containerFactory = Application.AMQ_FACTORY_BEAN)
	public void receive(String message) {
		LOG.info("received {}", message);
	}

	@JmsListener(destination = "validated", containerFactory = Application.AMQ_FACTORY_BEAN)
	public void receive(TextMessage message) throws Exception {
		LOG.info("received message {}", message);

		String text = message.getText();
		if (text.contains("kaputt")) {
			throw new IllegalStateException("Die Nachricht ist kaputt");
		}
	}
}