Git Product home page Git Product logo

mqtt-3.1.1-test's Introduction

Build Status

Synopsis

This project provides a simple example that shows how to use MQTT Paho Java 1.2.0 features of auto-reconnect and publish while offline. These features enhance the MQTT system high availability.

Motivation

This project is the base example from which interoperability with Solace message router high availability features of router redundancy and disaster recovery where tested.

Checking out and Building

This project depends on maven for building. To build the class locally, check out the project and build from source by doing the following:

git clone https://github.com/SolaceLabs/mqtt-3.1.1-test
cd /mqtt-3.1.1-test
mvn compile
  or
gradle build

Code Example

The interesting bits of code can be seen here, the initialize asyncClient, create host list with auto-reconnect and publish buffer:

public class SampleMqttClient implements MqttCallbackExtended {

connOpt = new MqttConnectOptions();
connOpt.setCleanSession(true);
connOpt.setKeepAliveInterval(30);
connOpt.setConnectionTimeout(60);
connOpt.setAutomaticReconnect(true);

String[] brokerList = new String[2];
brokerList[0] = BROKER_URL1;
brokerList[1] = BROKER_URL2;
connOpt.setServerURIs(brokerList);

DisconnectedBufferOptions bufferOpts = new DisconnectedBufferOptions();
bufferOpts.setBufferEnabled(true);
bufferOpts.setBufferSize(100);            // 100 message buffer
bufferOpts.setDeleteOldestMessages(true); // Purge oldest messages when buffer is full
bufferOpts.setPersistBuffer(false);       // Do not buffer to disk

try {
myClient = new MqttAsyncClient(brokerList[0], clientID, persistence);
myClient.setBufferOpts(bufferOpts);
myClient.setCallback(this);
            myClient.connect(connOpt);

Also there is a new callback on connection complete:

public void connectComplete(boolean reconnect, String serverURI) {
if (reconnect) {
System.out.println("Connection Reconnected! To: " + serverURI);
} else {
System.out.println("Initial Connection! To: " + serverURI);
}
addSubscriptions();
}

Tests

There are no tests with this project yet. Tests should be:

  1. Publish before initial connection. Async MQTT client calls connect then publish before connectComplete() is called.
  • Ensure message is stored as per persistent model then published once connection is established.
  1. Cause reconnection. Once connected, disconnect the client at the message broker.
  • Ensure the client reconnects, validate subscription still exists for Clean=0 and do not exist for clean=1.
  1. Publish while reconnecting. Connect client, publish at a rate of ~20/sec. Disconnect client at the broker.
  • Ensure reconnection and messages losslessly published in correct order.
  1. Cause failover. Once connected, shut down access to connected MQTT router.
  • Ensure failover to next broker in host list. Subscriptions should re-add as per clean flag.

Contributing

Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the Apache License, Version 2.0. - See the LICENSE file for details.

Resources

For more information about working with Paho MQTT APIs:

For more information about Solace technology in general please visit these resources:

mqtt-3.1.1-test's People

Contributors

kenbarr avatar mdspielman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.