io.github.springwolf.plugins.jms.producer.SpringwolfJmsProducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of springwolf-jms Show documentation
Show all versions of springwolf-jms Show documentation
Automated JSON API documentation for JMS Listeners built with Spring
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.plugins.jms.producer;
import jakarta.jms.JMSException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.core.JmsTemplate;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Slf4j
public class SpringwolfJmsProducer {
private final Optional template;
public SpringwolfJmsProducer(List templates) {
this.template = templates.isEmpty() ? Optional.empty() : Optional.of(templates.get(0));
}
public boolean isEnabled() {
return template.isPresent();
}
public void send(String channelName, Map headers, Object payload) {
if (template.isPresent()) {
template.get().convertAndSend(channelName, payload, message -> {
if (headers != null) {
headers.forEach((name, value) -> {
try {
message.setStringProperty(name, value);
} catch (JMSException ex) {
log.warn("Unable to set JMS Header key={} value={}", name, value, ex);
}
});
}
return message;
});
} else {
log.warn("JMS producer is not configured");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy