java - how should a message look like to be a response -
i have read , followed example in http://docs.spring.io/spring-integration/reference/html/ip.html#ip-correlation
i have spring-integration server
<int-ip:tcp-connection-factory id="socketserver" type="server" port="30124" using-nio="true" mapper="mapper" deserializer="jsonserializer" serializer="jsonserializer" single-use="false"/> with mapper above link:
<bean id="mapper" class="org.springframework.integration.ip.tcp.connection.messageconvertingtcpmessagemapper"> <constructor-arg name="messageconverter"> <bean class="org.springframework.integration.support.converter.mapmessageconverter"> <property name="headernames"> <list> <value>correlationid</value> <value>sequencenumber</value> <value>sequencesize</value> </list> </property> </bean> </constructor-arg>
with inbound , outbound adapter
<int-ip:tcp-inbound-channel-adapter id="inboundserver" channel="inputchannel" connection-factory="socketserver"/> <int-ip:tcp-outbound-channel-adapter id="outboundserver" channel="outputchannel" connection-factory="socketserver"/> <int:channel id="inputchannel"/> <int:channel id="outputchannel"/> <int:service-activator input-channel="inputchannel" output-channel="outputchannel" ref="echoservice" method="test"/> <bean id="echoservice" class="com.example.helloreply" /> i'm sending messages connected client with
map<string, object> headers = new hashmap<string, object>(); map msgmap = new hashmap(); msgmap.put("message", "test"); headers.put(ipheaders.connection_id, <the connection id>); headers.put("correlationid", "boo"); headers.put("sequencenumber", 100); headers.put("sequencesize", 5); message<map> msg = new genericmessage<map>(msgmap, headers); messagingtemplate template = new messagingtemplate(); message reply = template.sendandreceive(outputchannel, msg); the last line blocks forever, because can't figure out how reply message legacy client (telnet).
the sent message is:
{"headers":{"sequencenumber":101,"sequencesize":5,"correlationid":"boo"},"payload":{"message":"test"}} i thought correlationid , same sequencenumber match tried response client server with
{"headers":{"sequencenumber":101,"sequencesize":5,"correlationid":"boo"},"payload":{"result":"ok"}} but interpreted new inbound message, not recognized answer initial send-message.
so sendandreceive expect , there documentation/specification special usecase (sendandreceive communication non-spring clients).
what mean
channels "sendandreceive"
?
which apis using? unless use gateway, responsible reply correlation.
the tcp client-server multiplex sample shows 1 technique (an aggregator) correlate replies when not using gateway.
show complete configuration (edit question, don't add in comment; doesn't render well).
edit:
the framework can't correlation automatically (with template.sendandreceive()). doesn't know custom headers and, in case, there's no way reference automatic reply queue in template message.
you have write own code correlation.
template.send(...); // wait incoming message same correlation id for example, use, say, map<string, blockingqueue>, keyed correlation id , poll response.
invoke method in class via <service-activator/> , put reply blockingqueue correlation id. use map of queuechannels.
this use case (block thread waiting asynchronous event) has come several times , considering adding component make things easier.
Comments
Post a Comment