Add a constructor that lets users create a MessageHeaderAccessor object given only a headers map.

This is a small optimization in high volume scenarios to avoid creating unnecessary Message<?> objects when you only have a headers map.

The specific use case I'm looking at, is being able to create a MessageHeaderAccessor object to process headers from a "consolidated headers" object (such as from the Rabbit Binder or Solace Binder) created for a Message<List<?>> consumed from Spring Cloud Stream's batched consumers.

e.g.: Being able to do something like this:

@Bean
Consumer<Message<List<Payload>>> input() {
    return batchMsg -> {
        List<Payload> batchedPayloads = batchMsg.getPayload();
        List<Map<String, Object>> batchedHeaders = (List<Map<String, Object>>) batchMsg.getHeaders().get(SolaceBinderHeaders.BATCHED_HEADERS);

        for (int i = 0; i < batchedPayloads.size(); i++) {
            Map<String, Object> headersMap = batchedHeaders.get(i);
            MessageHeaderAccessor accessor = null;
            if (headersMap instanceof MessageHeaders headers) {
                accessor = MessageHeaderAccessor.getAccessor(headers, null);

            }
            if (accessor == null || || !headers.isMutable()) {
                accessor = new MessageHeaderAccessor(headersMap);
            }

            // Do some logic with the accessor
        }
    };
}

With the current implementation, instead of just being able to do:

MessageHeaderAccessor accessor = new MessageHeaderAccessor(headersMap);

I would need to do this, which is pointless if the accessor's constructor will just extract the headers from the Message<?>:

MessageHeaderAccessor accessor = new MessageHeaderAccessor(new GenericMessage<?>(payload, headersMap));

Comment From: pivotal-cla

@Nephery Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: snicoll

@Nephery thanks for the suggestion but until you have signed the CLA, we can't really continue this conversation here. One problem with your change is that there are now two constructors with a single argument that are nullable so this will break backward compatibility.

Comment From: Nephery

In that case, I'll close the PR and raise it as an issue.

About your concern, I was wondering if it was a concern as well. I have a potential suggestion to work around it, but lets continue that discussion in the issue once I raise it.