Howdy,
I sort of have this working, but when I want to send a message without it being a response to an incoming I get a spring exception.
Here is the scenario.
server is the spring integration app that creates 2 tcp server adapters as described in our previous messages in this thread.
The client app can send messages to both of the 2 tcp sockets, and the SI app can send replies to those incoming messages as a return value in the endpoint method.
Now I need to send a message out one of the tcp sockets asynchronously to send something to the client. This is when I get an exception.
Code:
org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.ip.tcp.TcpSendingMessageHandler#1]
Here is my relevant context file
Code:
<ip:tcp-connection-factory id="DebugEngineEventsFactory"
type="server"
port="${debug.engine.events.port}"
using-nio="false"
/>
<ip:tcp-outbound-channel-adapter id="EventsOutputAdapter"
channel="EventsOutputChannel"
connection-factory="DebugEngineEventsFactory"/>
<ip:tcp-inbound-channel-adapter id="EventsInputAdapter"
channel="EventsInputChannel"
connection-factory="DebugEngineEventsFactory"/>
<gateway id="StudioEventGateway" service-interface="com.hp.oo.studio.debug.engine.gateways.StudioGateway"
default-request-channel="SendEventsExecutorChannel" />
<chain input-channel="SendCommandsExecutorChannel" output-channel="CommandsOutputChannel">
<integration:object-to-json-transformer object-mapper="customObjectMapper"/>
<transformer expression="new String(payload)"/>
</chain>
<chain input-channel="EventsInputChannel" output-channel="ReceiveEventsExecutorChannel">
<transformer expression="new String(payload)"/>
<integration:json-to-object-transformer type="com.hp.oo.studio.debug.engine.shared.protocol.events.DebugEvent"
object-mapper="customObjectMapper" />
<header-enricher>
<header name="replyChannel" value="SendEventsExecutorChannel"/>
</header-enricher>
</chain>
<service-activator input-channel="ReceiveEventsExecutorChannel"
ref="DebugExecutorService"
method="eventFromStudio" />
Async java method
Code:
/**
* this method is run asynchronously as part of an event loop in the app
* itself. We need to send an "event" back to the client. But Spring
* fails to send the message, even though we successfully sent an
* message out the event channel already as a reply from an incoming
* message.
*
*/
void sendDebugEvent(IDebugEvent event, boolean error) {
if (debugMode) {
try {
//I tried this and it fails as well.
/*StudioEventGateway = (StudioGateway)context.getBean("StudioEventGateway");
StudioEventGateway.send(event);*/
//this doesn't work either.
ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
MessageChannel output = channelResolver.resolveChannelName("SendEventsExecutorChannel");
//exception here....
output.send(new GenericMessage<IDebugEvent>(event));
} catch (Exception e) {
System.err.println("Error: " + e);
System.exit(1);
}
} else if (error) {
System.err.println("Error: " + event);
}
}
/**
* THIS works...but is the input endpoint from the client.
* the reply object gets sent out the channel to the client.
*
*/
public IDebugEvent eventFromStudio(DebugEvent event) {
IDebugEvent responseEvent = new DebugEvent();
return responseEvent;
}