view spring-jms-playground/src/main/java/de/comline/jms/receiver/QueueReceiver.java @ 18:8504317b9a09

Erweiterung um Sleuth, manuelle Konfiguration von Spring
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 17 Sep 2020 09:03:11 +0200
parents a9675808f1dd
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");
		}
	}
}