Class DefaultPahoMessageConverter
java.lang.Object
org.springframework.integration.mqtt.support.DefaultPahoMessageConverter
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- MqttMessageConverter,- MessageConverter
public class DefaultPahoMessageConverter
extends Object
implements MqttMessageConverter, BeanFactoryAware
Default implementation for mapping to/from Messages.
- Since:
- 4.0
- Author:
- Gary Russell, Artem Bilan
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a converter with default options (qos=0, retain=false, charset=UTF-8).DefaultPahoMessageConverter(int defaultQos, boolean defaultRetained) Construct a converter to create outbound messages with the supplied default qos and retain settings and a UTF-8 charset for converting outbound String payloads tobyte[]and inboundbyte[]to String (unlesspayloadAdBytesis true).DefaultPahoMessageConverter(int defaultQos, boolean defaultRetained, String charset) Construct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.DefaultPahoMessageConverter(int defaultQos, MessageProcessor<Integer> qosProcessor, boolean defaultRetained, MessageProcessor<Boolean> retainedProcessor) Construct a converter to create outbound messages with the supplied default qos and retained message processors and a UTF-8 charset for converting outbound String payloads tobyte[]and inboundbyte[]to String (unlesspayloadAdBytesis true).DefaultPahoMessageConverter(int defaultQos, MessageProcessor<Integer> qosProcessor, boolean defaultRetained, MessageProcessor<Boolean> retainedProcessor, String charset) Construct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.DefaultPahoMessageConverter(String charset) Construct a converter with default options (qos=0, retain=false) and the supplied charset.
- 
Method SummaryModifier and TypeMethodDescriptionorg.eclipse.paho.client.mqttv3.MqttMessagefromMessage(Message<?> message, Class<?> targetClass) protected BeanFactoryprotected MessageBuilderFactorybooleanprotected byte[]messageToMqttBytes(Message<?> message) Subclasses can override this method to convert the payload to a byte[].protected ObjectmqttBytesToPayload(org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage) Subclasses can override this method to convert the byte[] to a payload.final voidsetBeanFactory(BeanFactory beanFactory) voidsetBytesMessageMapper(BytesMessageMapper bytesMessageMapper) Set aBytesMessageMapperto use when mapping byte[].voidsetPayloadAsBytes(boolean payloadAsBytes) True if the converter should not convert the message payload to a String.Message<?>toMessage(Object mqttMessage, MessageHeaders headers) toMessageBuilder(String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage) Convert to a message builder.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.integration.mqtt.support.MqttMessageConvertertoMessage
- 
Constructor Details- 
DefaultPahoMessageConverterpublic DefaultPahoMessageConverter()Construct a converter with default options (qos=0, retain=false, charset=UTF-8).
- 
DefaultPahoMessageConverterpublic DefaultPahoMessageConverter(int defaultQos, boolean defaultRetained) Construct a converter to create outbound messages with the supplied default qos and retain settings and a UTF-8 charset for converting outbound String payloads tobyte[]and inboundbyte[]to String (unlesspayloadAdBytesis true).- Parameters:
- defaultQos- the default qos.
- defaultRetained- the default retained.
 
- 
DefaultPahoMessageConverterConstruct a converter with default options (qos=0, retain=false) and the supplied charset.- Parameters:
- charset- the charset used to convert outbound String payloads to- byte[]and inbound- byte[]to String (unless- payloadAdBytesis true).
- Since:
- 4.1.2
 
- 
DefaultPahoMessageConverterConstruct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.- Parameters:
- defaultQos- the default qos.
- defaultRetained- the default retained.
- charset- the charset used to convert outbound String payloads to- byte[]and inbound- byte[]to String (unless- payloadAdBytesis true).
 
- 
DefaultPahoMessageConverterpublic DefaultPahoMessageConverter(int defaultQos, MessageProcessor<Integer> qosProcessor, boolean defaultRetained, MessageProcessor<Boolean> retainedProcessor) Construct a converter to create outbound messages with the supplied default qos and retained message processors and a UTF-8 charset for converting outbound String payloads tobyte[]and inboundbyte[]to String (unlesspayloadAdBytesis true).- Parameters:
- defaultQos- the default qos.
- qosProcessor- a message processor to determine the qos.
- defaultRetained- the default retained.
- retainedProcessor- a message processor to determine the retained flag.
- Since:
- 5.0
 
- 
DefaultPahoMessageConverterpublic DefaultPahoMessageConverter(int defaultQos, MessageProcessor<Integer> qosProcessor, boolean defaultRetained, MessageProcessor<Boolean> retainedProcessor, String charset) Construct a converter to create outbound messages with the supplied default qos and retain settings and the supplied charset.- Parameters:
- defaultQos- the default qos.
- qosProcessor- a message processor to determine the qos.
- defaultRetained- the default retained.
- retainedProcessor- a message processor to determine the retained flag.
- charset- the charset used to convert outbound String payloads to- byte[]and inbound- byte[]to String (unless- payloadAdBytesis true).
- Since:
- 5.0
 
 
- 
- 
Method Details- 
setBeanFactory- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
 
- 
getBeanFactory
- 
getMessageBuilderFactory
- 
setPayloadAsBytespublic void setPayloadAsBytes(boolean payloadAsBytes) True if the converter should not convert the message payload to a String. Ignored if aBytesMessageMapperis provided.- Parameters:
- payloadAsBytes- The payloadAsBytes to set.
- See Also:
 
- 
isPayloadAsBytespublic boolean isPayloadAsBytes()
- 
setBytesMessageMapperSet aBytesMessageMapperto use when mapping byte[].setPayloadAsBytes(boolean)is ignored when aBytesMessageMapperis provided.- Parameters:
- bytesMessageMapper- the mapper.
- Since:
- 5.0
- See Also:
 
- 
toMessage- Specified by:
- toMessagein interface- MessageConverter
 
- 
toMessageBuilderpublic AbstractIntegrationMessageBuilder<?> toMessageBuilder(String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage) Description copied from interface:MqttMessageConverterConvert to a message builder.- Specified by:
- toMessageBuilderin interface- MqttMessageConverter
- Parameters:
- topic- the topic.
- mqttMessage- the MQTT message.
- Returns:
- the builder.
 
- 
fromMessagepublic org.eclipse.paho.client.mqttv3.MqttMessage fromMessage(Message<?> message, Class<?> targetClass) - Specified by:
- fromMessagein interface- MessageConverter
 
- 
mqttBytesToPayloadSubclasses can override this method to convert the byte[] to a payload. The default implementation creates a String (default) or byte[].- Parameters:
- mqttMessage- The inbound message.
- Returns:
- The payload for the Spring integration message
 
- 
messageToMqttBytesSubclasses can override this method to convert the payload to a byte[]. The default implementation accepts a byte[] or String payload. If aBytesMessageMapperis provided, conversion to byte[] is delegated to it, so any payload that it can handle is supported.- Parameters:
- message- The outbound Message.
- Returns:
- The byte[] which will become the payload of the MQTT Message.
 
 
-