From 1eefab933965b855775fbc199c06c000b576b765 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 23 Jan 2014 18:57:55 -0500 Subject: [PATCH] INT-3239 MQTT Final Polishing For Master Merge * Final Polishing to move from extensions to master * Commit history is retained from the extensions * Docbook Chapter JIRA: https://jira.springsource.org/browse/INT-3239 --- build.gradle | 8 + settings.gradle | 1 + ...MqttMessageDrivenChannelAdapterParser.java | 7 +- .../mqtt/config/xml/MqttNamespaceHandler.java | 5 +- .../xml/MqttOutboundChannelAdapterParser.java | 7 +- .../mqtt/config/xml/MqttParserUtils.java | 7 +- .../core/DefaultMqttPahoClientFactory.java | 6 +- .../mqtt/core/MqttPahoClientFactory.java | 17 ++- ...stractMqttMessageDrivenChannelAdapter.java | 5 +- .../MqttPahoMessageDrivenChannelAdapter.java | 2 +- .../outbound/AbstractMqttMessageHandler.java | 7 +- .../mqtt/outbound/MqttPahoMessageHandler.java | 5 +- .../support/DefaultPahoMessageConverter.java | 67 +++++++-- .../integration/mqtt/support/MqttHeaders.java | 5 +- .../mqtt/support/MqttMessageConverter.java | 14 +- .../integration/mqtt/support/MqttUtils.java | 5 +- .../main/resources/META-INF/spring.schemas | 4 +- ....0.xsd => spring-integration-mqtt-4.0.xsd} | 0 .../mqtt/BackTobackAdapterTests.java | 4 +- .../integration/mqtt/BrokerRunning.java | 5 +- .../integration/mqtt/MqttAdapterTests.java | 4 +- ...essageDrivenChannelAdapterParserTests.java | 4 +- ...MqttOutboundChannelAdapterParserTests.java | 4 +- src/reference/docbook/index.xml | 1 + src/reference/docbook/mqtt.xml | 138 ++++++++++++++++++ src/reference/docbook/whats-new.xml | 12 ++ 26 files changed, 288 insertions(+), 56 deletions(-) rename spring-integration-mqtt/src/main/resources/org/springframework/integration/mqtt/config/xml/{spring-integration-mqtt-1.0.xsd => spring-integration-mqtt-4.0.xsd} (100%) create mode 100644 src/reference/docbook/mqtt.xml diff --git a/build.gradle b/build.gradle index 1fe57fcef0..286c5ce5e7 100644 --- a/build.gradle +++ b/build.gradle @@ -408,6 +408,14 @@ project('spring-integration-mongodb') { } } +project('spring-integration-mqtt') { + description = 'Spring Integration MQTT Support' + dependencies { + compile project(":spring-integration-core") + compile "org.eclipse.paho:mqtt-client:0.4.0" + } +} + project('spring-integration-redis') { description = 'Spring Integration Redis Support' dependencies { diff --git a/settings.gradle b/settings.gradle index ac37638a58..b8cf28024b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,6 +16,7 @@ include 'spring-integration-jmx' include 'spring-integration-jpa' include 'spring-integration-mail' include 'spring-integration-mongodb' +include 'spring-integration-mqtt' include 'spring-integration-redis' include 'spring-integration-rmi' include 'spring-integration-scripting' diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParser.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParser.java index 55b0717c63..bfb09f1a94 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParser.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,18 +15,19 @@ */ package org.springframework.integration.mqtt.config.xml; +import org.w3c.dom.Element; + import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractChannelAdapterParser; import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter; -import org.w3c.dom.Element; /** * The MqttAdapter Message Driven Channel adapter parser * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class MqttMessageDrivenChannelAdapterParser extends AbstractChannelAdapterParser { diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttNamespaceHandler.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttNamespaceHandler.java index ea99d71e67..d2b162a352 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttNamespaceHandler.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttNamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa * The namespace handler for the MqttAdapter namespace * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class MqttNamespaceHandler extends AbstractIntegrationNamespaceHandler { @@ -29,6 +29,7 @@ public class MqttNamespaceHandler extends AbstractIntegrationNamespaceHandler { /* (non-Javadoc) * @see org.springframework.beans.factory.xml.NamespaceHandler#init() */ + @Override public void init() { this.registerBeanDefinitionParser("message-driven-channel-adapter", new MqttMessageDrivenChannelAdapterParser()); this.registerBeanDefinitionParser("outbound-channel-adapter", new MqttOutboundChannelAdapterParser()); diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParser.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParser.java index e9635c8641..46cfde44c5 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParser.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package org.springframework.integration.mqtt.config.xml; +import org.w3c.dom.Element; + import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; @@ -22,13 +24,12 @@ import org.springframework.integration.config.xml.AbstractOutboundChannelAdapter import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler; import org.springframework.util.StringUtils; -import org.w3c.dom.Element; /** * The parser for the MqttAdapter Outbound Channel Adapter. * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class MqttOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttParserUtils.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttParserUtils.java index 123cf5fe1d..d4a24622d5 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttParserUtils.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/config/xml/MqttParserUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,12 @@ */ package org.springframework.integration.mqtt.config.xml; +import org.w3c.dom.Element; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.util.StringUtils; -import org.w3c.dom.Element; /** * Contains various utility methods for parsing Mqtt Adapter @@ -27,7 +28,7 @@ import org.w3c.dom.Element; * respective {@link BeanDefinition}s. * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public final class MqttParserUtils { diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/DefaultMqttPahoClientFactory.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/DefaultMqttPahoClientFactory.java index 2445bb401a..60d72b6619 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/DefaultMqttPahoClientFactory.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/DefaultMqttPahoClientFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,10 @@ import org.eclipse.paho.client.mqttv3.MqttException; /** * Creates a default {@link MqttClient} and a set of options as configured. + * * @author Gary Russell * @author Gunnar Hillert - * @since 1.0 + * @since 4.0 * */ public class DefaultMqttPahoClientFactory implements MqttPahoClientFactory { @@ -81,6 +82,7 @@ public class DefaultMqttPahoClientFactory implements MqttPahoClientFactory { /** * Will be used to set the "Last Will and Testament" (LWT) for the connection. + * @param will The will. * * @see MqttConnectOptions */ diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/MqttPahoClientFactory.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/MqttPahoClientFactory.java index d7dcf74155..8d86ae5c0c 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/MqttPahoClientFactory.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/MqttPahoClientFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,25 @@ import org.eclipse.paho.client.mqttv3.MqttException; /** * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public interface MqttPahoClientFactory { + /** + * Retrieve a client instance. + * + * @param url The URL. + * @param clientId The client id. + * @return The client instance. + * @throws MqttException Any. + */ MqttClient getClientInstance(String url, String clientId) throws MqttException; + /** + * Retrieve the connection options. + * + * @return The options. + */ MqttConnectOptions getConnectionOptions(); } diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java index 5e21c72c7e..e22d7720c5 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,9 @@ import org.springframework.util.Assert; /** * Abstract class for MQTT Message-Driven Channel Adapters. + * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public abstract class AbstractMqttMessageDrivenChannelAdapter extends MessageProducerSupport { diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java index 3ec866211e..d025376485 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java index 3dc72403ef..3cce15758a 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,19 @@ package org.springframework.integration.mqtt.outbound; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.springframework.context.SmartLifecycle; -import org.springframework.integration.MessageHandlingException; import org.springframework.integration.handler.AbstractMessageHandler; import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter; import org.springframework.integration.mqtt.support.MqttHeaders; import org.springframework.integration.mqtt.support.MqttMessageConverter; import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHandlingException; import org.springframework.util.Assert; /** * Abstract class for MQTT outbound channel adapters. + * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public abstract class AbstractMqttMessageHandler extends AbstractMessageHandler implements SmartLifecycle { diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/MqttPahoMessageHandler.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/MqttPahoMessageHandler.java index e0570be3a1..0460b59f00 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/MqttPahoMessageHandler.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/MqttPahoMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,9 @@ import org.springframework.util.Assert; /** * Eclipse Paho implementation. + * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class MqttPahoMessageHandler extends AbstractMqttMessageHandler diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java index 5f4a5f074c..539cc0811d 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,10 @@ import org.springframework.util.Assert; /** - * Default implementation allowing most connection options to be configured. + * Default implementation for mapping to/from Messages. + * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class DefaultPahoMessageConverter implements MqttMessageConverter { @@ -38,6 +39,8 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter { private final Boolean defaultRetained; + private volatile boolean payloadAsBytes = false; + public DefaultPahoMessageConverter() { this (0, false); } @@ -46,6 +49,15 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter { this(defaultQos, defaultRetain, "UTF-8"); } + /** + * True if the converter should not convert the message payload to a String. + * + * @param payloadAsBytes The payloadAsBytes to set. + */ + protected final void setPayloadAsBytes(boolean payloadAsBytes) { + this.payloadAsBytes = payloadAsBytes; + } + public DefaultPahoMessageConverter(int defaultQos, boolean defaultRetained, String charset) { this.defaultQos = defaultQos; this.defaultRetained = defaultRetained; @@ -59,9 +71,9 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter { } @Override - public Message toMessage(String topic, MqttMessage mqttMessage) { + public Message toMessage(String topic, MqttMessage mqttMessage) { try { - MessageBuilder messageBuilder = MessageBuilder.withPayload(new String(mqttMessage.getPayload(), this.charset)) + MessageBuilder messageBuilder = MessageBuilder.withPayload(mqttBytesToPayload(mqttMessage)) .setHeader(MqttHeaders.QOS, mqttMessage.getQos()) .setHeader(MqttHeaders.DUPLICATE, mqttMessage.isDuplicate()) .setHeader(MqttHeaders.RETAINED, mqttMessage.isRetained()); @@ -77,6 +89,42 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter { @Override public MqttMessage fromMessage(Message message, Class targetClass) { + byte[] payloadBytes = messageToMqttBytes(message); + MqttMessage mqttMessage = new MqttMessage(payloadBytes); + Object header = message.getHeaders().get(MqttHeaders.RETAINED); + Assert.isTrue(header == null || header instanceof Boolean, MqttHeaders.RETAINED + " header must be Boolean"); + mqttMessage.setRetained(header == null ? this.defaultRetained : (Boolean) header); + header = message.getHeaders().get(MqttHeaders.QOS); + Assert.isTrue(header == null || header instanceof Integer, MqttHeaders.QOS + " header must be Integer"); + mqttMessage.setQos(header == null ? this.defaultQos : (Integer) header); + return mqttMessage; + } + + /** + * Subclasses can override this method to convert the byte[] to a payload. + * The default implementation creates a String (default) or byte[]. + * + * @param mqttMessage The inbound message. + * @return The payload for the Spring integration message + * @throws Exception Any. + */ + protected Object mqttBytesToPayload(MqttMessage mqttMessage) throws Exception { + if (this.payloadAsBytes) { + return mqttMessage.getPayload(); + } + else { + return new String(mqttMessage.getPayload(), this.charset); + } + } + + /** + * Subclasses can override this method to convert the payload to a byte[]. + * The default implementation accepts a byte[] or String payload. + * + * @param payload The payload. + * @return The byte[] + */ + protected byte[] messageToMqttBytes(Message message) { Object payload = message.getPayload(); Assert.isTrue(payload instanceof byte[] || payload instanceof String); byte[] payloadBytes; @@ -91,14 +139,7 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter { else { payloadBytes = (byte[]) payload; } - MqttMessage mqttMessage = new MqttMessage(payloadBytes); - Object header = message.getHeaders().get(MqttHeaders.RETAINED); - Assert.isTrue(header == null || header instanceof Boolean, MqttHeaders.RETAINED + " header must be Boolean"); - mqttMessage.setRetained(header == null ? this.defaultRetained : (Boolean) header); - header = message.getHeaders().get(MqttHeaders.QOS); - Assert.isTrue(header == null || header instanceof Integer, MqttHeaders.QOS + " header must be Integer"); - mqttMessage.setQos(header == null ? this.defaultQos : (Integer) header); - return mqttMessage; + return payloadBytes; } } diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttHeaders.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttHeaders.java index b114ad6cf2..6873c776d6 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttHeaders.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,8 @@ package org.springframework.integration.mqtt.support; /** * Spring Integration headers. * @author Gary Russell - * @since 3.0 + * + * @since 4.0 * */ public class MqttHeaders { diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttMessageConverter.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttMessageConverter.java index aefbff36e3..c21b322ab0 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttMessageConverter.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,19 @@ import org.springframework.messaging.converter.MessageConverter; /** * Extension of {@link MessageConverter} allowing the topic to be added as * a header. + * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public interface MqttMessageConverter extends MessageConverter { - Message toMessage(String topic, MqttMessage mqttMessage); + /** + * Convert to a Message. + * + * @param topic The topic. + * @param mqttMessage The MQTT message. + * @return The Message. + */ + Message toMessage(String topic, MqttMessage mqttMessage); } diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttUtils.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttUtils.java index 1f69d23cd6..b943298eff 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttUtils.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,12 +20,11 @@ package org.springframework.integration.mqtt.support; * Contains utility methods used by the MqttAdapter components. * * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public final class MqttUtils { - /** Prevent instantiation. */ private MqttUtils() { throw new AssertionError(); } diff --git a/spring-integration-mqtt/src/main/resources/META-INF/spring.schemas b/spring-integration-mqtt/src/main/resources/META-INF/spring.schemas index f4273c569a..275cfb4314 100644 --- a/spring-integration-mqtt/src/main/resources/META-INF/spring.schemas +++ b/spring-integration-mqtt/src/main/resources/META-INF/spring.schemas @@ -1,2 +1,2 @@ -http\://www.springframework.org/schema/integration/mqtt/spring-integration-mqtt-1.0.xsd=org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-1.0.xsd -http\://www.springframework.org/schema/integration/mqtt/spring-integration-mqtt.xsd=org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-1.0.xsd +http\://www.springframework.org/schema/integration/mqtt/spring-integration-mqtt-4.0.xsd=org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-4.0.xsd +http\://www.springframework.org/schema/integration/mqtt/spring-integration-mqtt.xsd=org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-4.0.xsd diff --git a/spring-integration-mqtt/src/main/resources/org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-1.0.xsd b/spring-integration-mqtt/src/main/resources/org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-4.0.xsd similarity index 100% rename from spring-integration-mqtt/src/main/resources/org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-1.0.xsd rename to spring-integration-mqtt/src/main/resources/org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-4.0.xsd diff --git a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BackTobackAdapterTests.java b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BackTobackAdapterTests.java index 45a17f8793..3f4b52eb69 100644 --- a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BackTobackAdapterTests.java +++ b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BackTobackAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; /** * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class BackTobackAdapterTests { diff --git a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BrokerRunning.java b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BrokerRunning.java index 57587d84da..e9be4042c7 100644 --- a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BrokerRunning.java +++ b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/BrokerRunning.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,11 +28,12 @@ import org.eclipse.paho.client.mqttv3.MqttException; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.junit.runners.model.Statement; + import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory; /** * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class BrokerRunning extends TestWatcher { diff --git a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.java b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.java index e55800eda2..d6fc8d9857 100644 --- a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.java +++ b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; /** * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ public class MqttAdapterTests { diff --git a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParserTests.java b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParserTests.java index 00d4fe50f7..17b8a2ce3c 100644 --- a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParserTests.java +++ b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttMessageDrivenChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ @ContextConfiguration diff --git a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParserTests.java b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParserTests.java index bea91f5573..9e96cde631 100644 --- a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParserTests.java +++ b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell - * @since 1.0 + * @since 4.0 * */ @ContextConfiguration diff --git a/src/reference/docbook/index.xml b/src/reference/docbook/index.xml index de8b8b7f1e..718034e8fd 100644 --- a/src/reference/docbook/index.xml +++ b/src/reference/docbook/index.xml @@ -135,6 +135,7 @@ + diff --git a/src/reference/docbook/mqtt.xml b/src/reference/docbook/mqtt.xml new file mode 100644 index 0000000000..0fa5c25ab5 --- /dev/null +++ b/src/reference/docbook/mqtt.xml @@ -0,0 +1,138 @@ + + + MQTT Support + +
+ Introduction + + Spring Integration provides inbound and outbound channel adapters supporting the + MQ Telemetry Transport (MQTT) protocol. The current implementation uses the + Eclipse Paho MQTT Client + library. + + + Configuration of both adapters is achieved using the + DefaultMqttPahoClientFactory. + Refer to the Paho documentation for more information about configuration + options. + +
+ +
+ Inbound (message-driven) Channel Adapter + + The inbound channel adapter is implemented by the + MqttPahoMessageDrivenChannelAdapter. For convenience, it + can be configured using the namespace. A minimal configuration might be: + + + + + + +]]> + + Attributes: + + ]]> + + + The client id. + + + The broker URL. + + + A comma delimited list of topics from which this adapter will receive messages. + + + An MqttMessageConverter (optional). The default + DefaultPahoMessageConverter produces a message with a String + payload (by default) with the following headers: + + mqtt_topic - the topic from which the message was received + mqtt_duplicate - true if the message is a duplicate + mqtt_qos - the quality of service + + The DefaultPahoMessageConverter can be configured to return the raw + byte[] in the payload by declaring it as a <bean/> and setting the + payloadAsBytes property. + + + The client factory. + + + The send timeout - only applies if the channel might block (such as a bounded QueueChannel + that is currently full). + + +
+ +
+ Outbound Channel Adapter + + The outbound channel adapter is implemented by the MqttPahoMessageHandler which + is wrapped in a ConsumerEndpoint. For convenience, it + can be configured using the namespace. + + + Attributes: + + ]]> + + + The client id. + + + The broker URL. + + + An MqttMessageConverter (optional). The default + DefaultPahoMessageConverter + recognizes the following headers: + + mqtt_topic - the topic to which the message will be sent + mqtt_retained - true if the message is to be retained + mqtt_qos - the quality of service + + + + The client factory. + + + The default quality of service (used if no mqtt_qos header is found). Not allowed + if a custom converter is supplied. + + + The default value of the retained flag (used if no mqtt_retaind header is found). Not allowed + if a custom converter is supplied. + + + The default topic to which the message will be sent (used if no mqtt_topic header is found). + + +
+ +
diff --git a/src/reference/docbook/whats-new.xml b/src/reference/docbook/whats-new.xml index 7fccdfdb40..882d6c9d67 100644 --- a/src/reference/docbook/whats-new.xml +++ b/src/reference/docbook/whats-new.xml @@ -9,6 +9,18 @@ in more details, please see the Issue Tracker tickets that were resolved as part of the 4.0 development process. +
+ New Components +
+ MQTT Channel Adapters + + The MQTT channel adapters (previously available in the Spring Integration Extensions repository) + are now available as part of the normal Spring Integration distribution. + See + +
+
+
General Changes