I am using Spring Boot 1.4.1-RELEASE and RabbitMQ 3.2.3. My Application class looks like this -
#SpringBootApplication
#EnableAutoConfiguration
public class EventStoreMessageDeliveryApplication {
public final static String queueName = "customer.default.queue"; // spring-boot
#Bean
Queue queue() {
return new Queue(queueName, true);
}
#Bean
FanoutExchange exchange() {
return new FanoutExchange("customer.events.fanout.exchange", true, false); // spring-boot-exchange
}
#Bean
Binding binding() {
return new Binding(queueName, Binding.DestinationType.QUEUE, "customer.events.fanout.exchange", "*.*", null);
}
#Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
connectionFactory.setPublisherConfirms(true);
return connectionFactory;
}
#Bean
SimpleMessageListenerContainer container(MessageListenerAdapter listenerAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory());
container.setQueueNames(queueName);
container.setMessageListener(listenerAdapter);
container.setRecoveryBackOff(new ExponentialBackOff(3000, 2));
return container;
}
#Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
return new MessageListenerAdapter(receiver, "receiveMessage");
}
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(EventStoreMessageDeliveryApplication.class, args);
}
}
And my listener class looks like -
#Component
public class Receiver {
private CountDownLatch latch = new CountDownLatch(1);
public void receiveMessage(String message) {
System.out.println("Received <" + message + ">");
// do something
latch.countDown();
}
public CountDownLatch getLatch() {
return latch;
}
}
I want to handle the exceptions like connection refused which may come when the broker is down. How can I handle such exceptions? I am not sure where I can get the handle for the exceptions.
You can create a SimpleRabbitListenerContainerFactory. This is basically a listener for events from RabbitConnectionFactory.
#Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setErrorHandler(rabbitErrorHandler());
return factory;
}
rabbitErrorHandler() can return a bean of implementation of org.springframework.util.ErrorHandler.
Reference docs
I have a suggestion and it could work out. Since you want to have an exception of connection refused against the RabbitMQ broker, it is up to the client to catch the exception.
In your example, which looks like the one from SpringIO docs, I would assume you could make the exception handling in the main (not recommended though):
#Component
public class Runner implements CommandLineRunner {
private final RabbitTemplate rabbitTemplate;
private final Receiver receiver;
public Runner(Receiver receiver, RabbitTemplate rabbitTemplate) {
this.receiver = receiver;
this.rabbitTemplate = rabbitTemplate;
}
#Override
public void run(String... args) throws Exception {
System.out.println("Sending message...");
try {
rabbitTemplate.convertAndSend(Application.topicExchangeName, "foo.bar.baz", "Hello from RabbitMQ!");
receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
}catch(AmqpException the_exception) {
System.out.printl("Connection refused. Problem thrown when trying to connecto the RabbitMQ");
}
}
}
The AmqpException comes from the docs of the convertAndSend() method, which is being thrown if something went bad. Here you can capture your own custom message.
I hope this is what you are looking for or atleast guides you the correct destination.
/A
Related
trace:
org.apache.camel.FailedToStartRouteException: Failed to start route FromSAA because of null
at org.apache.camel.impl.engine.RouteService.setUp(RouteService.java:132)
at org.apache.camel.impl.engine.InternalRouteStartupManager.doInitRoutes(InternalRouteStartupManager.java:92)
at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2949)
at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2630)
at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2649)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:262)
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:119)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:151)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at ru.rbru.fms.router.Bootstrap.main(Bootstrap.java:13)
Caused by: java.lang.IllegalArgumentException: connectionFactory must be specified
at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:156)
at org.apache.camel.component.jms.JmsConfiguration.createConnectionFactory(JmsConfiguration.java:1746)
at org.apache.camel.component.jms.JmsConfiguration.getOrCreateConnectionFactory(JmsConfiguration.java:856)
at org.apache.camel.component.jms.JmsConfiguration.createListenerConnectionFactory(JmsConfiguration.java:1754)
at org.apache.camel.component.jms.JmsConfiguration.getOrCreateListenerConnectionFactory(JmsConfiguration.java:900)
at org.apache.camel.component.jms.JmsConfiguration.configureMessageListenerContainer(JmsConfiguration.java:1582)
at org.apache.camel.component.jms.JmsConfiguration.createMessageListenerContainer(JmsConfiguration.java:786)
at org.apache.camel.component.jms.JmsEndpoint.createMessageListenerContainer(JmsEndpoint.java:157)
at org.apache.camel.component.jms.JmsEndpoint.createConsumer(JmsEndpoint.java:152)
at org.apache.camel.component.jms.JmsEndpoint.createConsumer(JmsEndpoint.java:69)
at org.apache.camel.impl.engine.DefaultRoute.gatherRootServices(DefaultRoute.java:636)
at org.apache.camel.impl.engine.DefaultRoute.gatherServices(DefaultRoute.java:620)
at org.apache.camel.impl.engine.DefaultRoute.initializeServices(DefaultRoute.java:205)
at org.apache.camel.impl.engine.RouteService.doSetup(RouteService.java:151)
at org.apache.camel.impl.engine.RouteService.setUp(RouteService.java:130)
... 23 common frames omitted
My configurations:
#Component
#RequiredArgsConstructor
public class IbmMqInitializer {
private static final String ACKNOWLEDGEMENT_MODE = "CLIENT_ACKNOWLEDGE";
public void configure(CamelContext context, IbmMqProperties ibmMqProperties, ConnectionFactory connectionFactory) throws JMSException {
registerIbmMq(context, ibmMqProperties, connectionFactory);
}
private void registerIbmMq(CamelContext context, IbmMqProperties ibmMqProperties, ConnectionFactory connectionFactory) {
registerComponent(context, connectionFactory, ibmMqProperties);
}
private void registerComponent(CamelContext context,
ConnectionFactory connectionFactory,
IbmMqProperties ibmMqProperties) {
ComponentsBuilderFactory.jms()
.connectionFactory(connectionFactory)
.acknowledgementModeName(ACKNOWLEDGEMENT_MODE)
.concurrentConsumers(ibmMqProperties.getConcurrentConsumersCount())
.register(context, ibmMqProperties.getQueue());
}
}
#Configuration
public class ApplicationConfig {
private static final Integer CCSID_UTF_8 = 1208;
#Bean
#ConfigurationProperties("resources.ibm.mq.saa")
public IbmMqProperties saaIbmMqProps() {
return new IbmMqProperties();
}
#Bean
#ConfigurationProperties("resources.ibm.mq.esb")
public IbmMqProperties esbIbmMqProps() {
return new IbmMqProperties();
}
#Bean
public ConnectionFactory saaIbmMqFactory(#Qualifier("saaIbmMqProps") IbmMqProperties ibmMqProperties) throws JMSException {
return getMqQueueConnectionFactory(ibmMqProperties);
}
#Bean
public ConnectionFactory esbIbmMqFactory(#Qualifier("esbIbmMqProps") IbmMqProperties ibmMqProperties) throws JMSException {
return getMqQueueConnectionFactory(ibmMqProperties);
}
private ConnectionFactory getMqQueueConnectionFactory(IbmMqProperties ibmMqProperties) throws JMSException {
var factory = new MQQueueConnectionFactory();
factory.setCCSID(CCSID_UTF_8);
factory.setTransportType(CommonConstants.WMQ_CM_CLIENT);
factory.setHostName(ibmMqProperties.getHostName());
factory.setPort(ibmMqProperties.getPort());
factory.setChannel(ibmMqProperties.getChannel());
factory.setQueueManager(ibmMqProperties.getQueueManager());
return factory;
}
}
#Configuration
#RequiredArgsConstructor
#Slf4j
public class MqConfiguration {
private final IbmMqInitializer ibmMqInitializer;
#Bean
public CamelContextConfiguration contextConfiguration(#Qualifier("saaIbmMqProps") IbmMqProperties saaIbmMqProps,
#Qualifier("saaIbmMqFactory") ConnectionFactory saaIbmMqFactory,
#Qualifier("esbIbmMqProps") IbmMqProperties esbIbmMqProps,
#Qualifier("esbIbmMqFactory") ConnectionFactory esbIbmMqFactory) {
return new CamelContextConfiguration() {
#Override
public void beforeApplicationStart(CamelContext context) {
try {
ibmMqInitializer.configure(context, saaIbmMqProps, saaIbmMqFactory);
ibmMqInitializer.configure(context, esbIbmMqProps, esbIbmMqFactory);
} catch (JMSException e) {
log.error("Failed to connect to MQ", e);
}
}
#Override
public void afterApplicationStart(CamelContext camelContext) {
}
};
}
}
If I use only one ConnectionFactory there is no problem, but as soon as I add one more, e.g.:
#Bean
public ConnectionFactory saaIbmMqFactory(#Qualifier("saaIbmMqProps") IbmMqProperties ibmMqProperties) throws JMSException {
return getMqQueueConnectionFactory(ibmMqProperties);
}
#Service
public class SaaRoute extends RouteBuilder {
public static final String STATUS = "status";
private final SaaProcessor processor;
private final IbmMqProperties saaIbmMqProperties;
private final IbmMqProperties esbIbmMqProperties;
public SaaRoute(SaaProcessor processor,
#Qualifier("saaIbmMqProps") IbmMqProperties saaIbmMqProperties,
#Qualifier("esbIbmMqProps") IbmMqProperties esbIbmMqProperties) {
this.processor = processor;
this.saaIbmMqProperties = saaIbmMqProperties;
this.esbIbmMqProperties = esbIbmMqProperties;
}
#Override
public void configure() {
from(saaIbmMqProperties.getQueue()).routeId("FromSAA")
.log(LoggingLevel.DEBUG, log, "New message received")
.process(processor)
.choice()
.when(exchange -exchange.getProperty(STATUS).equals(MessageStatus.SUCCESSFULLY_PARSED))
.to(esbIbmMqProperties.getQueue())
.otherwise()
.log("Message was not converted")
.endChoice();
}
}
I get exceptions that mentioned before.
What could cause this exception?
If you are using the camel-jms-starter component, it tries to auto discover the ConnectionFactory. If only one ConnectionFactory object is present in the registry, it is used by default. But when multiple factories are present, it has to be specified on the route using the connectionFactory endpoint property.
from(jms:destinationType:destinationName?
connectionFactory=#saaIbmMqFactory)
.log(LoggingLevel.DEBUG, log, "New message received")
.process(processor)
.choice()
.when(exchange ->
exchange.getProperty(STATUS)
.equals(MessageStatus.SUCCESSFULLY_PARSED))
.to(esbIbmMqProperties.getQueue())
.otherwise()
.log("Message was not converted")
.endChoice();
If I had to guess now without trying to reproduce the code, I think it is because of the parameters you're passing to the register method call in this code
private void registerComponent(CamelContext context,
ConnectionFactory connectionFactory,
IbmMqProperties ibmMqProperties) {
ComponentsBuilderFactory.jms()
.connectionFactory(connectionFactory)
.acknowledgementModeName(ACKNOWLEDGEMENT_MODE)
.concurrentConsumers(ibmMqProperties.getConcurrentConsumersCount())
.register(context, ibmMqProperties.getQueue());
}
The doc for the register method specifies the second parameter as component name and you're passing your whole queue name. Camel uses component "names" to resolve which component will handle a certain route. So if you write:
.to("jms:queueName....")
Camel will look up what component is registered with the name "jms" - which is by default the JmsComponent, but nothing is stopping you from registering a JmsComponent with a name "myJmsComponent" so you can write:
.to("myJmsComponent:queueName")
What's happening in your case is you're registering a component with a name of your queue instead of what you think you're doing - registering a different connection factory for a different queues.
If you want to keep using this ComponentBuilderFactory pattern what I would suggest is to rewrite your initialiser class like this:
#Component
#RequiredArgsConstructor
public class IbmMqInitializer {
private static final String ACKNOWLEDGEMENT_MODE = "CLIENT_ACKNOWLEDGE";
public void configure(CamelContext context, IbmMqProperties ibmMqProperties, ConnectionFactory connectionFactory, String componentName) throws JMSException {
registerIbmMq(context, ibmMqProperties, connectionFactory, componentName);
}
private void registerIbmMq(CamelContext context, IbmMqProperties ibmMqProperties, ConnectionFactory connectionFactory, String componentName) {
registerComponent(context, connectionFactory, ibmMqProperties, componentName);
}
private void registerComponent(CamelContext context,
ConnectionFactory connectionFactory,
IbmMqProperties ibmMqProperties
String componentName) {
ComponentsBuilderFactory.jms()
.connectionFactory(connectionFactory)
.acknowledgementModeName(ACKNOWLEDGEMENT_MODE)
.concurrentConsumers(ibmMqProperties.getConcurrentConsumersCount())
.register(context, componentName);
}
}
And then call it like this:
try {
ibmMqInitializer.configure(context, saaIbmMqProps, saaIbmMqFactory, "saa");
ibmMqInitializer.configure(context, esbIbmMqProps, esbIbmMqFactory, "esb");
} catch (JMSException e) {
log.error("Failed to connect to MQ", e);
}
Then change your properties so your method IbmMqProperties::getQueue() returns routes starting with saa: and esb: instead of what you have now, which is probably jms:... for both.
So saa:sourceQueueName and esb:destQueueName.
I have created a new spring application which will push messages to a rabbitmq server.
My rabbitMQConfig java file looks like this :
#Configuration
public class RabbitMQConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQConfig.class);
#Value("${spring.rabbitmq.host}")
private String SPRING_RABBITMQ_HOST;
#Value("${spring.rabbitmq.port}")
private int SPRING_RABBITMQ_PORT;
#Value("${spring.rabbitmq.username}")
private String SPRING_RABBITMQ_USERNAME;
#Value("${spring.rabbitmq.password}")
private String SPRING_RABBITMQ_PASSWORD;
#Bean
public RabbitTemplate rabbitTemplate(){
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(SPRING_RABBITMQ_HOST,SPRING_RABBITMQ_PORT);
connectionFactory.setUsername(SPRING_RABBITMQ_USERNAME);
connectionFactory.setPassword(SPRING_RABBITMQ_PASSWORD);
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setExchange("my.controller.exchange");
rabbitTemplate.setRoutingKey("my.controller.key");
return rabbitTemplate;
}
#Bean
DirectExchange exchange() {
return new DirectExchange("my.controller.exchange", true, false);
}
#Bean
public Queue queue() {
return new Queue("my.controller", true);
}
#Bean
Binding exchangeBinding(DirectExchange exchange, Queue queue) {
return BindingBuilder.bind(queue).to(exchange).with("my.controller.key");
}
}
Here is how I push message to the queue :
#Service
public class RabbitPublisher {
#Autowired
private RabbitTemplate rabbitTemplate;
private static Logger LOGGER = Logger.getLogger(RabbitPublisher.class);
public Boolean pushToMyQueue(HashMap<String, Object> message) {
try {
rabbitTemplate.convertAndSend("my.controller.exchange","my.controller.key",message);
return true;
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("Error in pushing to my queue", e);
}
return false;
}
}
Since the exchange and queue are non-existent on the rabbitmq server, I expect them to be created automatically and message to be pushed. But it results in the following error :
ERROR 18198 --- [168.201.18:5672] o.s.a.r.c.CachingConnectionFactory :
Channel shutdown: channel error; protocol method: #method<channel.close>
(reply-code=404, reply-text=NOT_FOUND - no exchange
'my.controller.exchange' in vhost '/', class-id=60, method-id=40)
When I create the exchange and queue and bind them manually on the server, a message gets pushed successfully.
Please let me know if I am missing something. Thanks.
You need to add a RabbitAdmin #Bean. The admin will declare the elements when a connection is first opened.
You have to add AmqpAdmin admin bean with your required connection factory as below:
#Bean(name = "pimAmqpAdmin")
public AmqpAdmin pimAmqpAdmin(#Qualifier("defaultConnectionFactory") ConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
}
I am getting this exception after some 2-3 minutes of proper run of my app on cloud.I added timeout : 180 in manifest.yml file but the error still persists.
On STS console, I get the log as :
Execution failed for task ':cfPush'.> Application TestApp start timed out
Can anyone help me out in this please
Code:
#SpringBootApplication
public class SftpJavaApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SftpJavaApplication.class)
.web(false)
.run(args);
}
#Bean
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost("ip");
factory.setPort(port);
factory.setUser("user");
factory.setPassword("pwd");
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<LsEntry>(factory);
}
#Bean
#Transformer(inputChannel = "stream",outputChannel="data")
public org.springframework.integration.transformer.Transformer transformer () {
return new org.springframework.integration.transformer.StreamTransformer("UTF-8");
}
#Bean
#InboundChannelAdapter(value = "stream", poller = #Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource<InputStream> ftpMessageSource() {
SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template(), null);
messageSource.setRemoteDirectory("/test1/test2/test3");
messageSource.setFilter(new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(),
"streaming"));
return messageSource;
}
#Bean
public SftpRemoteFileTemplate template() {
return new SftpRemoteFileTemplate(sftpSessionFactory());
}
#Bean
#ServiceActivator(inputChannel = "data" )
public MessageHandler handler() {
return new MessageHandler() {
#Override
public void handleMessage(Message<?> message) throws MessagingException {
System.out.println(">>>>>>>>>>>>>"+message.getPayload()); //instead of a print the message is published to rabbit mq
}
};
}
}
There is another class which connects to a rabbit mq service on cloud and consumes the message
I'm trying to set up topic exchange on my spring app.
Here's my context configuration:
#Configuration
public class IntegrationConfig {
public final static String queueName = "my-queue";
#Bean
AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
}
#Bean
Queue queue() {
return new Queue(queueName);
}
#Bean
TopicExchange exchange() {
return new TopicExchange("my-exchange", false, true);
}
#Bean
Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with("ru.interosite.*");
}
#Bean
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(queueName);
container.setMessageListener(listenerAdapter);
return container;
}
#Bean
ImageUploadReceiver receiver() {
return new ImageUploadReceiver();
}
#Bean
MessageListenerAdapter listenerAdapter(ImageUploadReceiver receiver) {
return new MessageListenerAdapter(receiver, "receiveMessage");
}
}
This is receiver class:
public class ImageUploadReceiver {
private CountDownLatch latch = new CountDownLatch(1);
public void receiveMessage(String message) {
System.out.println("Received ");
latch.countDown();
}
public CountDownLatch getLatch() {
return latch;
}
}
This is sender code:
#RequestMapping("/sendmessage")
#ResponseBody
public String sendMessage() {
rabbitTemplate.convertAndSend("ru.interosite.1", "ttt1233");
try {
imageUploadReceiver.getLatch().await(3, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "Msg received";
}
So I'm sending message to topic exchange using binding key "ru.interosite.1" to the queue that was bound with pattern "ru.interosite.*". I used these key and pattern when tried sample from https://www.rabbitmq.com/tutorials/tutorial-five-java.html and they worked fine.
But inside String AMQP it does not work, i.e. receiver never gets called. It called only if binding key and pattern are completely the same as if I were using DirectExchange.
Am I missing something here?
You don't show the config for the RabbitTemplate, but I guess it is with default options.
To send a message to the my-exchange you must specify it directly:
rabbitTemplate.convertAndSend("my-exchange", "ru.interosite.1", "ttt1233");
You can also set the exchange in the rabbit template like this:
#Configuration
public class IntegrationConfig {
// ... as above
#Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setExchange("my-exchange");
return template;
}
}
So you can send the message with:
public class MyController {
#Autowired
RabbitTemplate rabbitTemplate;
#RequestMapping("/sendmessage")
#ResponseBody
public String sendMessage() {
rabbitTemplate.convertAndSend("ru.interosite.1", "ttt1233");
// ... as above
}
}
I am using spring boot as per examples for TcpInboundGateway, but have discovered the behaviour is slightly different than a hand coded a piece of TCP code I am replacing.
Specifically when using netcat, nc exits before receiving an answer, because the TcpInboundGateway read steam is closed, before any write occurs, causing nc to exit.
Can closing the read stream be delayed until the write has completed?
Here is the code:
#Configuration
#EnableIntegration
#ComponentScan
#EnableAutoConfiguration
public class Application {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class);
}
#Bean
TcpNetServerConnectionFactory cf () {
return new TcpNetServerConnectionFactory(9876);
}
#Bean
TcpInboundGateway tcpGate() {
TcpInboundGateway gateway = new TcpInboundGateway();
gateway.setConnectionFactory(cf());
gateway.setRequestChannel(requestChannel());
return gateway;
}
#Bean
public MessageChannel requestChannel() {
return new DirectChannel();
}
#MessageEndpoint
public static class Echo {
#ServiceActivator(inputChannel = "requestChannel")
public String echo(byte [] in) {
return "echo: " + new String(in);
}
}
#Autowired
private Environment env;
}
So I figured out it was probably the stream terminator character. Did some fiddling and found that using ByteArrayRawSerializer solves my problem.
#Bean TcpNetServerConnectionFactory cf () {
TcpNetServerConnectionFactory tcpNetServerConnectionFactory = new TcpNetServerConnectionFactory(9876);
tcpNetServerConnectionFactory.setDeserializer(new ByteArrayRawSerializer());
return tcpNetServerConnectionFactory;
}