Spring Integration
  1. Spring Integration
  2. INT-1807

Add Support to TCP Endpoints to Send/Receive Entire Message

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 2.0.3
    • Fix Version/s: 3.0 M3
    • Component/s: TCP/UDP Support
    • Labels:

      Description

      Add attribute 'extract-payload' (default=true) similar to JMS endpoints, to tcp connection factories, supporting the transfer of the complete message.

      Notes:

      If extract-payload is false, switch default (de)serializer from ByteArrayCrLfSerializer to Default(De)Serializer (java serialization).

      Assign a new message id when deserializing a complete message; put the id from the transmitted message into a header tcp_remote_message_id.

      Support for UDP is covered under a separate JIRA (INT-1808) because it's more complex; those adapters don't currently support pluggable serializers.

        Activity

        Hide
        Oleg Zhurakousky added a comment -

        Would also be nice to allow to specify message-converter as we do with other adapters. The typical use case might be that the Stream coming in might be a JSON stream representing a Message as String:

        {"headers":{"requestChannel":"inputChannel"},"payload":"Hello"}
        

        Obviously the above could be easily understood and converted to an SI Message with simple converter:

        try {
           ObjectMapper mapper = new ObjectMapper();
           JsonNode incommingMessageNode = mapper.readTree(new String((byte[])inputMessage.getPayload()));
           String requestChannel = incommingMessageNode.get("headers").get("requestChannel").getTextValue();
           String payload = incommingMessageNode.get("payload").getTextValue();
           return MessageBuilder.withPayload(payload).copyHeaders(inputMessage.getHeaders()).setHeader("requestChannel", requestChannel).build();
        } catch (Exception e) {
           throw new MessageTransformationException(inputMessage, "Failed to transform message", e);
        }
        

        And of course it could be more generic to handle multiple headers.

        Also, playing with Redis, i realized that the same strategy could be used there since Redis Message only has body represented as byte[], but could also receive a JSON string that represents and SI Message.

        Show
        Oleg Zhurakousky added a comment - Would also be nice to allow to specify message-converter as we do with other adapters. The typical use case might be that the Stream coming in might be a JSON stream representing a Message as String: { "headers" :{ "requestChannel" : "inputChannel" }, "payload" : "Hello" } Obviously the above could be easily understood and converted to an SI Message with simple converter: try { ObjectMapper mapper = new ObjectMapper(); JsonNode incommingMessageNode = mapper.readTree( new String (( byte [])inputMessage.getPayload())); String requestChannel = incommingMessageNode.get( "headers" ).get( "requestChannel" ).getTextValue(); String payload = incommingMessageNode.get( "payload" ).getTextValue(); return MessageBuilder.withPayload(payload).copyHeaders(inputMessage.getHeaders()).setHeader( "requestChannel" , requestChannel).build(); } catch (Exception e) { throw new MessageTransformationException(inputMessage, "Failed to transform message" , e); } And of course it could be more generic to handle multiple headers. Also, playing with Redis, i realized that the same strategy could be used there since Redis Message only has body represented as byte[], but could also receive a JSON string that represents and SI Message.
        Hide
        Gary Russell added a comment -

        Bumping to 3.0 - this issue has a number of votes.

        Show
        Gary Russell added a comment - Bumping to 3.0 - this issue has a number of votes.
        Hide
        Gary Russell added a comment -

        PR: https://github.com/SpringSource/spring-integration/pull/763

        Final implementation differs from above description. A combination of a MessageConvertingTcpMessageMapper, used with MapMessageConverter presents a Map object (containing the payload and selected headers) to the Serializer. Users can chose to write their own (de)serializer implementation to format the map on the wire. In addition a MapJsonSerializer is provided.

        Show
        Gary Russell added a comment - PR: https://github.com/SpringSource/spring-integration/pull/763 Final implementation differs from above description. A combination of a MessageConvertingTcpMessageMapper , used with MapMessageConverter presents a Map object (containing the payload and selected headers) to the Serializer . Users can chose to write their own (de)serializer implementation to format the map on the wire. In addition a MapJsonSerializer is provided.

          People

          • Assignee:
            Gary Russell
            Reporter:
            Gary Russell
          • Votes:
            6 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 2d
              2d
              Remaining:
              Remaining Estimate - 2d
              2d
              Logged:
              Time Spent - Not Specified
              Not Specified