Cleanup - SStill W.I.P
Signed-off-by: Jem Day <Jem.Day@cliffhanger.com>
This commit is contained in:
parent
de2b76a5ef
commit
c949073f04
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.core;
|
package io.cloudevents.mqtt.core;
|
||||||
|
|
||||||
import io.cloudevents.SpecVersion;
|
import io.cloudevents.SpecVersion;
|
||||||
|
@ -25,9 +41,10 @@ public abstract class BaseMqttBinaryMessageReader extends BaseGenericBinaryMessa
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the binary message reader.
|
* Initialise the binary message reader.
|
||||||
* @param version The CloudEvent message version.
|
*
|
||||||
|
* @param version The CloudEvent message version.
|
||||||
* @param contentType The assigned media content type.
|
* @param contentType The assigned media content type.
|
||||||
* @param payload The raw data payload from the MQTT message.
|
* @param payload The raw data payload from the MQTT message.
|
||||||
*/
|
*/
|
||||||
protected BaseMqttBinaryMessageReader(final SpecVersion version, final String contentType, final byte[] payload) {
|
protected BaseMqttBinaryMessageReader(final SpecVersion version, final String contentType, final byte[] payload) {
|
||||||
super(version, payload != null && payload.length > 0 ? BytesCloudEventData.wrap(payload) : null);
|
super(version, payload != null && payload.length > 0 ? BytesCloudEventData.wrap(payload) : null);
|
||||||
|
@ -82,6 +99,7 @@ public abstract class BaseMqttBinaryMessageReader extends BaseGenericBinaryMessa
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit each MQTT user-property and invoke the supplied function.
|
* Visit each MQTT user-property and invoke the supplied function.
|
||||||
|
*
|
||||||
* @param fn The function to invoke for each MQTT User property.
|
* @param fn The function to invoke for each MQTT User property.
|
||||||
*/
|
*/
|
||||||
protected abstract void forEachUserProperty(BiConsumer<String, Object> fn);
|
protected abstract void forEachUserProperty(BiConsumer<String, Object> fn);
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.core;
|
package io.cloudevents.mqtt.core;
|
||||||
|
|
||||||
import io.cloudevents.core.format.EventFormat;
|
import io.cloudevents.core.format.EventFormat;
|
||||||
|
@ -8,9 +24,10 @@ import io.cloudevents.core.provider.EventFormatProvider;
|
||||||
*/
|
*/
|
||||||
public class MqttUtils {
|
public class MqttUtils {
|
||||||
|
|
||||||
private MqttUtils() {}
|
private static final String DEFAULT_FORMAT = "application/cloudevents+json";
|
||||||
|
|
||||||
private static final String DEFAULT_FORMAT = "application/cloudevents+json";
|
private MqttUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the {@link EventFormat} to use when working with MQTT V3
|
* Obtain the {@link EventFormat} to use when working with MQTT V3
|
||||||
|
@ -18,7 +35,7 @@ public class MqttUtils {
|
||||||
*
|
*
|
||||||
* @return An event format.
|
* @return An event format.
|
||||||
*/
|
*/
|
||||||
public static EventFormat getDefaultEventFormat () {
|
public static EventFormat getDefaultEventFormat() {
|
||||||
|
|
||||||
return EventFormatProvider.getInstance().resolveFormat(DEFAULT_FORMAT);
|
return EventFormatProvider.getInstance().resolveFormat(DEFAULT_FORMAT);
|
||||||
|
|
||||||
|
@ -26,6 +43,7 @@ public class MqttUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default content type to assume for MQTT messages.
|
* Get the default content type to assume for MQTT messages.
|
||||||
|
*
|
||||||
* @return A Content-Type
|
* @return A Content-Type
|
||||||
*/
|
*/
|
||||||
public static final String getDefaultContentType() {
|
public static final String getDefaultContentType() {
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;
|
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.datatypes.MqttUtf8String;
|
import com.hivemq.client.mqtt.datatypes.MqttUtf8String;
|
||||||
|
@ -20,7 +36,6 @@ import java.util.Optional;
|
||||||
* A factory to obtain:
|
* A factory to obtain:
|
||||||
* - {@link MessageReader} instances to read CloudEvents from MQTT messages.
|
* - {@link MessageReader} instances to read CloudEvents from MQTT messages.
|
||||||
* - {@link MessageWriter} instances to write CloudEvents into MQTT messages.
|
* - {@link MessageWriter} instances to write CloudEvents into MQTT messages.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MqttMessageFactory {
|
public class MqttMessageFactory {
|
||||||
|
|
||||||
|
@ -74,7 +89,7 @@ public class MqttMessageFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link MessageWriter} for an MQTT V3 Message.
|
* Create a {@link MessageWriter} for an MQTT V3 Message.
|
||||||
*
|
* <p>
|
||||||
* Only supports structured messages.
|
* Only supports structured messages.
|
||||||
*
|
*
|
||||||
* @param builder {@link Mqtt3PublishBuilder.Complete}
|
* @param builder {@link Mqtt3PublishBuilder.Complete}
|
||||||
|
@ -89,6 +104,7 @@ public class MqttMessageFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the value of the CloudEvent 'specversion' in the MQTT V5 User Properties.
|
* Find the value of the CloudEvent 'specversion' in the MQTT V5 User Properties.
|
||||||
|
*
|
||||||
* @param message An MQTT message.
|
* @param message An MQTT message.
|
||||||
* @return spec version attribute content.
|
* @return spec version attribute content.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3PublishBuilder;
|
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3PublishBuilder;
|
||||||
|
@ -20,21 +36,21 @@ class V3MessageWriter implements MessageWriter<CloudEventWriter<Mqtt3PublishBuil
|
||||||
@Override
|
@Override
|
||||||
public CloudEventWriter<Mqtt3PublishBuilder> create(SpecVersion version) throws CloudEventRWException {
|
public CloudEventWriter<Mqtt3PublishBuilder> create(SpecVersion version) throws CloudEventRWException {
|
||||||
// No-Op
|
// No-Op
|
||||||
return null;
|
throw CloudEventRWException.newOther("Internal Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mqtt3PublishBuilder setEvent(EventFormat format, byte[] value) throws CloudEventRWException {
|
public Mqtt3PublishBuilder setEvent(EventFormat format, byte[] value) throws CloudEventRWException {
|
||||||
// No-Op
|
// No-Op
|
||||||
return null;
|
throw CloudEventRWException.newOther("Internal Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mqtt3PublishBuilder writeStructured(CloudEvent event, String format) {
|
public Mqtt3PublishBuilder writeStructured(CloudEvent event, String format) {
|
||||||
EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(format);
|
final EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(format);
|
||||||
|
|
||||||
if (eventFormat != null) {
|
if (eventFormat != null) {
|
||||||
return writeStructured(event, EventFormatProvider.getInstance().resolveFormat(format));
|
return writeStructured(event, eventFormat);
|
||||||
} else {
|
} else {
|
||||||
throw CloudEventRWException.newOther("Unsupported Format: " + format);
|
throw CloudEventRWException.newOther("Unsupported Format: " + format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5PublishBuilder;
|
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5PublishBuilder;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
/**
|
/**
|
||||||
* This module implements the MQTT binding specification using the
|
* This module implements the MQTT binding specification using the
|
||||||
* HiveMQ MQTT client library.
|
* HiveMQ MQTT client library.
|
||||||
*
|
* <p>
|
||||||
* Use the {@link io.cloudevents.mqtt.hivemq.MqttMessageFactory} to obtain
|
* Use the {@link io.cloudevents.mqtt.hivemq.MqttMessageFactory} to obtain
|
||||||
* CloudEvent reader and writer instances.
|
* CloudEvent reader and writer instances.
|
||||||
*
|
* <p>
|
||||||
* Both V3 and V5 versions of MQTT are supported.
|
* Both V3 and V5 versions of MQTT are supported.
|
||||||
*
|
*
|
||||||
* @since 2.5.0
|
* @since 2.5.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
|
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
|
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
|
import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt5.datatypes.Mqtt5UserProperty;
|
import com.hivemq.client.mqtt.mqtt5.datatypes.Mqtt5UserProperty;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.hivemq;
|
package io.cloudevents.mqtt.hivemq;
|
||||||
|
|
||||||
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;
|
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.SpecVersion;
|
import io.cloudevents.SpecVersion;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import org.eclipse.paho.mqttv5.common.MqttMessage;
|
import org.eclipse.paho.mqttv5.common.MqttMessage;
|
||||||
|
|
|
@ -1,9 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.CloudEvent;
|
import io.cloudevents.CloudEvent;
|
||||||
import io.cloudevents.SpecVersion;
|
import io.cloudevents.SpecVersion;
|
||||||
import io.cloudevents.core.format.EventFormat;
|
import io.cloudevents.core.format.EventFormat;
|
||||||
import io.cloudevents.core.format.EventSerializationException;
|
|
||||||
import io.cloudevents.core.message.MessageWriter;
|
import io.cloudevents.core.message.MessageWriter;
|
||||||
import io.cloudevents.core.provider.EventFormatProvider;
|
import io.cloudevents.core.provider.EventFormatProvider;
|
||||||
import io.cloudevents.mqtt.core.MqttUtils;
|
import io.cloudevents.mqtt.core.MqttUtils;
|
||||||
|
@ -13,7 +28,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link MessageWriter} that writes an CloudEvent to a V3 MQTT Message.
|
* A {@link MessageWriter} that writes an CloudEvent to a V3 MQTT Message.
|
||||||
*
|
* <p>
|
||||||
* Note: This only supports Structured messages in JSON format as defined
|
* Note: This only supports Structured messages in JSON format as defined
|
||||||
* by the MQTT CloudEvent binding specification.
|
* by the MQTT CloudEvent binding specification.
|
||||||
*/
|
*/
|
||||||
|
@ -28,8 +43,9 @@ class V3MessageWriter implements MessageWriter<CloudEventWriter<MqttMessage>, Mq
|
||||||
/**
|
/**
|
||||||
* Ensure the supplied content type is appropriate for V3 messages
|
* Ensure the supplied content type is appropriate for V3 messages
|
||||||
* as-per binding specification.
|
* as-per binding specification.
|
||||||
*
|
* <p>
|
||||||
* Raises exception if not valid.
|
* Raises exception if not valid.
|
||||||
|
*
|
||||||
* @param contentType
|
* @param contentType
|
||||||
*/
|
*/
|
||||||
private void ensureValidContent(String contentType) {
|
private void ensureValidContent(String contentType) {
|
||||||
|
|
|
@ -1,10 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.core.format.EventFormat;
|
|
||||||
import io.cloudevents.core.message.MessageReader;
|
import io.cloudevents.core.message.MessageReader;
|
||||||
import io.cloudevents.core.message.MessageWriter;
|
import io.cloudevents.core.message.MessageWriter;
|
||||||
import io.cloudevents.core.message.impl.GenericStructuredMessageReader;
|
import io.cloudevents.core.message.impl.GenericStructuredMessageReader;
|
||||||
import io.cloudevents.core.provider.EventFormatProvider;
|
|
||||||
import io.cloudevents.mqtt.core.MqttUtils;
|
import io.cloudevents.mqtt.core.MqttUtils;
|
||||||
import io.cloudevents.rw.CloudEventWriter;
|
import io.cloudevents.rw.CloudEventWriter;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.CloudEventData;
|
import io.cloudevents.CloudEventData;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.core.message.MessageReader;
|
import io.cloudevents.core.message.MessageReader;
|
||||||
|
@ -7,9 +23,6 @@ import io.cloudevents.core.message.impl.MessageUtils;
|
||||||
import io.cloudevents.core.v1.CloudEventV1;
|
import io.cloudevents.core.v1.CloudEventV1;
|
||||||
import io.cloudevents.rw.CloudEventWriter;
|
import io.cloudevents.rw.CloudEventWriter;
|
||||||
import org.eclipse.paho.mqttv5.common.MqttMessage;
|
import org.eclipse.paho.mqttv5.common.MqttMessage;
|
||||||
import org.eclipse.paho.mqttv5.common.packet.UserProperty;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MQTT V5 factory to :
|
* MQTT V5 factory to :
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* This module implements the MQTT binding specification using the
|
* This module implements the MQTT binding specification using the
|
||||||
* Paho MQTT client library.
|
* Paho MQTT client library.
|
||||||
*
|
* <p>
|
||||||
* Separate factories are provided for MQTT V3 and V5.
|
* Separate factories are provided for MQTT V3 and V5.
|
||||||
*
|
*
|
||||||
* @since 2.5.0
|
* @since 2.5.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import org.eclipse.paho.mqttv5.common.MqttMessage;
|
import org.eclipse.paho.mqttv5.common.MqttMessage;
|
||||||
|
|
|
@ -1,32 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.CloudEvent;
|
import io.cloudevents.CloudEvent;
|
||||||
import io.cloudevents.SpecVersion;
|
|
||||||
import io.cloudevents.core.format.EventDeserializationException;
|
import io.cloudevents.core.format.EventDeserializationException;
|
||||||
import io.cloudevents.core.format.EventSerializationException;
|
|
||||||
import io.cloudevents.core.message.Encoding;
|
|
||||||
import io.cloudevents.core.message.MessageReader;
|
import io.cloudevents.core.message.MessageReader;
|
||||||
import io.cloudevents.core.message.MessageWriter;
|
import io.cloudevents.core.message.MessageWriter;
|
||||||
import io.cloudevents.core.mock.CSVFormat;
|
import io.cloudevents.core.mock.CSVFormat;
|
||||||
import io.cloudevents.core.test.Data;
|
import io.cloudevents.core.test.Data;
|
||||||
import io.cloudevents.core.v03.CloudEventV03;
|
|
||||||
import io.cloudevents.rw.CloudEventRWException;
|
import io.cloudevents.rw.CloudEventRWException;
|
||||||
import io.cloudevents.types.Time;
|
|
||||||
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
import java.beans.EventSetDescriptor;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public class V3MessageFactoryTest {
|
public class V3MessageFactoryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -64,7 +66,7 @@ public class V3MessageFactoryTest {
|
||||||
MessageReader reader = V3MqttMessageFactory.createReader(m);
|
MessageReader reader = V3MqttMessageFactory.createReader(m);
|
||||||
Assertions.assertNotNull(reader);
|
Assertions.assertNotNull(reader);
|
||||||
|
|
||||||
// This should fail
|
// This should fail
|
||||||
// Expect an exception
|
// Expect an exception
|
||||||
|
|
||||||
Assertions.assertThrows(EventDeserializationException.class, () -> {
|
Assertions.assertThrows(EventDeserializationException.class, () -> {
|
||||||
|
|
|
@ -1,11 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.CloudEvent;
|
import io.cloudevents.CloudEvent;
|
||||||
import io.cloudevents.core.format.EventFormat;
|
import io.cloudevents.core.format.EventFormat;
|
||||||
import io.cloudevents.core.message.MessageReader;
|
import io.cloudevents.core.message.MessageReader;
|
||||||
import io.cloudevents.core.message.MessageWriter;
|
import io.cloudevents.core.message.MessageWriter;
|
||||||
import io.cloudevents.core.mock.CSVFormat;
|
|
||||||
import io.cloudevents.core.provider.EventFormatProvider;
|
|
||||||
import io.cloudevents.core.test.Data;
|
import io.cloudevents.core.test.Data;
|
||||||
import io.cloudevents.jackson.JsonFormat;
|
import io.cloudevents.jackson.JsonFormat;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
|
@ -25,6 +39,23 @@ import java.util.stream.Stream;
|
||||||
public class V3RoundTripTests {
|
public class V3RoundTripTests {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test set is limited owing to the the fact that:
|
||||||
|
* (a) We only support JSON Format
|
||||||
|
* (b) Round-tripping of events with JSON 'data' doesn't reliably work owing to the way the equality tests work on the event.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static Stream<CloudEvent> simpleEvents() {
|
||||||
|
return Stream.of(
|
||||||
|
Data.V03_MIN,
|
||||||
|
Data.V03_WITH_TEXT_DATA,
|
||||||
|
Data.V1_MIN,
|
||||||
|
Data.V1_WITH_TEXT_DATA,
|
||||||
|
Data.V1_WITH_XML_DATA
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("simpleEvents")
|
@MethodSource("simpleEvents")
|
||||||
public void roundTrip(CloudEvent ce) {
|
public void roundTrip(CloudEvent ce) {
|
||||||
|
@ -53,20 +84,4 @@ public class V3RoundTripTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This test set is limited owing to the the fact that:
|
|
||||||
* (a) We only support JSON Format
|
|
||||||
* (b) Round-tripping of events with JSON 'data' doesn't reliably work owing to the way the equality tests work on the event.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static Stream<CloudEvent> simpleEvents() {
|
|
||||||
return Stream.of(
|
|
||||||
Data.V03_MIN,
|
|
||||||
Data.V03_WITH_TEXT_DATA,
|
|
||||||
Data.V1_MIN,
|
|
||||||
Data.V1_WITH_TEXT_DATA,
|
|
||||||
Data.V1_WITH_XML_DATA
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.CloudEvent;
|
import io.cloudevents.CloudEvent;
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018-Present The CloudEvents Authors
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package io.cloudevents.mqtt.paho;
|
package io.cloudevents.mqtt.paho;
|
||||||
|
|
||||||
import io.cloudevents.CloudEvent;
|
import io.cloudevents.CloudEvent;
|
||||||
|
|
|
@ -32,7 +32,8 @@ Using the Java SDK you can:
|
||||||
| AMQP Protocol Binding | :x: | :x: |
|
| AMQP Protocol Binding | :x: | :x: |
|
||||||
| - [Proton](amqp-proton.md) | :heavy_check_mark: | :heavy_check_mark: |
|
| - [Proton](amqp-proton.md) | :heavy_check_mark: | :heavy_check_mark: |
|
||||||
| MQTT Protocol Binding | :x: | :x: |
|
| MQTT Protocol Binding | :x: | :x: |
|
||||||
| - [Paho](mqtt-paho.md) | :heavy_check_mark: | :heavy_check_mark: |
|
| - [Paho](mqtt.md) | :heavy_check_mark: | :heavy_check_mark: |
|
||||||
|
| - [HiveMQ](mqtt.md) | :heavy_check_mark: | :heavy_check_mark: |
|
||||||
| AVRO Event Format | :x: | :x: |
|
| AVRO Event Format | :x: | :x: |
|
||||||
| HTTP Protocol Binding | :heavy_check_mark: | :heavy_check_mark: |
|
| HTTP Protocol Binding | :heavy_check_mark: | :heavy_check_mark: |
|
||||||
| - [Vert.x](http-vertx.md) | :heavy_check_mark: | :heavy_check_mark: |
|
| - [Vert.x](http-vertx.md) | :heavy_check_mark: | :heavy_check_mark: |
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
---
|
|
||||||
title: CloudEvents MQTT (Paho)
|
|
||||||
nav_order: 5
|
|
||||||
---
|
|
||||||
|
|
||||||
# CloudEvents MQTT Paho
|
|
||||||
|
|
||||||
This module implements `MessageReader` and `MessageWriter` using the Paho
|
|
||||||
library.
|
|
||||||
|
|
||||||
It currently only support MQTT Version 5.
|
|
||||||
|
|
||||||
For Maven based projects, use the following to include the `Paho` MQTT Binding
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.cloudevents</groupId>
|
|
||||||
<artifactId>cloudevents-mqtt-paho</artifactId>
|
|
||||||
<version>2.5.0</version>
|
|
||||||
</dependency>
|
|
||||||
```
|
|
||||||
|
|
||||||
# Sending & Receiving CloudEvents
|
|
||||||
|
|
||||||
The `PahoMessageFactory` provides methods to create CloudEvent `MessageReader` and `MessageWriter`
|
|
||||||
instances that are used to encode and decode CloudEvents into MQTT messages.
|
|
||||||
|
|
||||||
```java
|
|
||||||
public final class PahoMessageFactory {
|
|
||||||
|
|
||||||
public static MessageReader createReader(MqttMessage mqttMessage);
|
|
||||||
|
|
||||||
public static MessageWriter createWriter();
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Reading CloudEvents
|
|
||||||
|
|
||||||
## Sending CloudEvents
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
---
|
||||||
|
title: CloudEvents MQTT
|
||||||
|
nav_order: 5
|
||||||
|
---
|
||||||
|
|
||||||
|
# MQTT Support
|
||||||
|
|
||||||
|
The SDK supports both V3 and V5 MQTT binding specifications via these Java client libraries:
|
||||||
|
|
||||||
|
* [Paho]()
|
||||||
|
* [HiveMQ]()
|
||||||
|
|
||||||
|
NOTE: MQTT V3 *only* supports structured mode transfer of CloudEVents. Operations related to binary mode transmission
|
||||||
|
are either not available or will throw runtime exceptions if an attempt is made to use them.
|
||||||
|
|
||||||
|
Both client library implementations rely on a *provided* maven dependency.
|
||||||
|
|
||||||
|
# General Usage
|
||||||
|
|
||||||
|
There is a slight variance in usage between the two supported client libraries owing to the way those clients
|
||||||
|
have implemented support for the two versions of MQTT but the general pattern is the same as every other protocol
|
||||||
|
binding.
|
||||||
|
|
||||||
|
## Creating a message from a CloudEvent
|
||||||
|
|
||||||
|
1. Obtain a `MessageWriter` from a factory.
|
||||||
|
2. Use the writer to populate the MQTT message using structured or binary mode.
|
||||||
|
* `mqttMessage = messageWriter.writeBinary(cloudEvent);` or,
|
||||||
|
* `mqttMessage = messageWriter.writeStructured(cloudEvent, eventFormat);`
|
||||||
|
|
||||||
|
## Creating a CloudEvent from a message.
|
||||||
|
|
||||||
|
1. Obtain a 'MessageReader' from a message factory for an MQTT message.
|
||||||
|
2. Obtain a CloudEvent from the reader.
|
||||||
|
* _CloudEvent cloudEvent = reader.toEvent();_
|
||||||
|
|
||||||
|
|
||||||
|
# PAHO Client Usage
|
||||||
|
|
||||||
|
## Maven
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.cloudevents</groupId>
|
||||||
|
<artifactId>cloudevents-mqtt-paho</artifactId>
|
||||||
|
<version>2.x.y</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
# HiveMQ Client Usage
|
||||||
|
|
||||||
|
## Maven
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.cloudevents</groupId>
|
||||||
|
<artifactId>cloudevents-mqtt-hivemq</artifactId>
|
||||||
|
<version>2.x.y</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
Loading…
Reference in New Issue