项目作者: ctron

项目描述 :
A Gateway Client SDK for Eclipse Kapua™
高级语言: Java
项目地址: git://github.com/ctron/kapua-gateway-client.git
创建时间: 2017-05-16T16:08:13Z
项目社区:https://github.com/ctron/kapua-gateway-client

开源协议:Other

下载


Eclipse Kapua™ Gateway Client SDK Build status Maven Central

This project provides an SDK for connecting to Eclipse Kapua as a gateway.

Note: This is not part of the Eclipse Kapua project.

This project should provide a simple to use SDK for pushing telemetry data into Kapua
and consuming command messages out of Kapua.

Note: This is a work in progress and should not be considered production ready.

How to use

The following quick steps should provide you with a working example.

Add to your Maven project

  1. <dependency>
  2. <groupId>de.dentrassi.kapua</groupId>
  3. <artifactId>kapua-gateway-client-provider-mqtt-fuse</artifactId>
  4. <version><!-- replace with current version --></version>
  5. </dependency>
  6. <dependency>
  7. <groupId>de.dentrassi.kapua</groupId>
  8. <artifactId>kapua-gateway-client-profile-kura</artifactId>
  9. <version><!-- replace with current version --></version>
  10. </dependency>

Example client

  1. import static org.eclipse.kapua.gateway.client.Credentials.userAndPassword;
  2. import static org.eclipse.kapua.gateway.client.Errors.ignore;
  3. import org.eclipse.kapua.gateway.client.mqtt.fuse.FuseClient;
  4. import org.eclipse.kapua.gateway.client.profile.kura.KuraMqttProfile;
  5. try (Client client = KuraMqttProfile.newProfile(FuseClient.Builder::new)
  6. .accountName("kapua-sys")
  7. .clientId("foo-bar-1")
  8. .brokerUrl("tcp://localhost:1883")
  9. .credentials(userAndPassword("kapua-broker", "kapua-password"))
  10. .build()) {
  11. try (Application application = client.buildApplication("app1").build()) {
  12. // subscribe to a topic
  13. application.data(Topic.of("my", "receiver")).subscribe(message -> {
  14. System.out.format("Received: %s%n", message);
  15. });
  16. // cache sender instance
  17. Sender<RuntimeException> sender = application
  18. .data(Topic.of("my", "sender"))
  19. .errors(ignore());
  20. int i = 0;
  21. while (true) {
  22. // send
  23. sender.send(Payload.of("counter", i++));
  24. Thread.sleep(1000);
  25. }
  26. }
  27. }