Java Code Examples for org.springframework.messaging.MessageHeaders#getOrDefault()

The following examples show how to use org.springframework.messaging.MessageHeaders#getOrDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendToMethodReturnValueHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getTemplateVariables(MessageHeaders headers) {
	String name = DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER;
	return (Map<String, String>) headers.getOrDefault(name, Collections.emptyMap());
}
 
Example 2
Source File: SendToMethodReturnValueHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getTemplateVariables(MessageHeaders headers) {
	String name = DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER;
	return (Map<String, String>) headers.getOrDefault(name, Collections.emptyMap());
}
 
Example 3
Source File: RocketMQUtil.java    From rocketmq-spring with Apache License 2.0 4 votes vote down vote up
private static Message getAndWrapMessage(String destination, MessageHeaders headers, byte[] payloads) {
    if (destination == null || destination.length() < 1) {
        return null;
    }
    if (payloads == null || payloads.length < 1) {
        return null;
    }
    String[] tempArr = destination.split(":", 2);
    String topic = tempArr[0];
    String tags = "";
    if (tempArr.length > 1) {
        tags = tempArr[1];
    }
    Message rocketMsg = new Message(topic, tags, payloads);
    if (Objects.nonNull(headers) && !headers.isEmpty()) {
        Object keys = headers.get(RocketMQHeaders.KEYS);
        if (!StringUtils.isEmpty(keys)) { // if headers has 'KEYS', set rocketMQ message key
            rocketMsg.setKeys(keys.toString());
        }
        Object flagObj = headers.getOrDefault("FLAG", "0");
        int flag = 0;
        try {
            flag = Integer.parseInt(flagObj.toString());
        } catch (NumberFormatException e) {
            // Ignore it
            if (log.isInfoEnabled()) {
                log.info("flag must be integer, flagObj:{}", flagObj);
            }
        }
        rocketMsg.setFlag(flag);
        Object waitStoreMsgOkObj = headers.getOrDefault("WAIT_STORE_MSG_OK", "true");
        rocketMsg.setWaitStoreMsgOK(Boolean.TRUE.equals(waitStoreMsgOkObj));
        headers.entrySet().stream()
            .filter(entry -> !Objects.equals(entry.getKey(), "FLAG")
                && !Objects.equals(entry.getKey(), "WAIT_STORE_MSG_OK")) // exclude "FLAG", "WAIT_STORE_MSG_OK"
            .forEach(entry -> {
                if (!MessageConst.STRING_HASH_SET.contains(entry.getKey())) {
                    rocketMsg.putUserProperty(entry.getKey(), String.valueOf(entry.getValue()));
                }
            });

    }
    return rocketMsg;
}