centrifuge-java

Java client to communicate with Centrifugo over Websockets..

License

License

Categories

Categories

Java Languages
GroupId

GroupId

org.coindirect
ArtifactId

ArtifactId

centrifuge-java
Last Version

Last Version

0.38
Release Date

Release Date

Type

Type

jar
Description

Description

centrifuge-java
Java client to communicate with Centrifugo over Websockets..
Project URL

Project URL

https://github.com/donald-jackson/centrifuge-java
Source Code Management

Source Code Management

https://github.com/donald-jackson/centrifuge-java

Download centrifuge-java

How to add to project

<!-- https://jarcasting.com/artifacts/org.coindirect/centrifuge-java/ -->
<dependency>
    <groupId>org.coindirect</groupId>
    <artifactId>centrifuge-java</artifactId>
    <version>0.38</version>
</dependency>
// https://jarcasting.com/artifacts/org.coindirect/centrifuge-java/
implementation 'org.coindirect:centrifuge-java:0.38'
// https://jarcasting.com/artifacts/org.coindirect/centrifuge-java/
implementation ("org.coindirect:centrifuge-java:0.38")
'org.coindirect:centrifuge-java:jar:0.38'
<dependency org="org.coindirect" name="centrifuge-java" rev="0.38">
  <artifact name="centrifuge-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.coindirect', module='centrifuge-java', version='0.38')
)
libraryDependencies += "org.coindirect" % "centrifuge-java" % "0.38"
[org.coindirect/centrifuge-java "0.38"]

Dependencies

compile (4)

Group / Artifact Type Version
org.java-websocket : Java-WebSocket jar 1.3.0
com.google.code.findbugs : jsr305 jar 3.0.1
org.slf4j : slf4j-api jar 1.7.25
org.json : json jar 20180130

test (6)

Group / Artifact Type Version
junit : junit jar 4.12
org.robolectric : robolectric jar 3.0
org.mockito : mockito-core jar 2.19.1
com.squareup.okhttp3 : okhttp jar 3.2.0
com.squareup.okhttp : mockwebserver jar 2.7.5
commons-codec : commons-codec jar 1.9

Project Modules

There are no modules declared in this project.

centrifuge-java

Centrifugo java client

This is forked from the android client with android specific code refactored.

Usage

Create client and connect:
String centrifugoAddress = "wss://centrifugo.herokuapp.com/connection/websocket";
String userId = "...";
String userToken = "..."; //nullable
String token = "...";
String tokenTimestamp = "...";
Centrifugo centrifugo = new Centrifugo.Builder(centrifugoAddress)
                        .setUser(new User(userId, userToken))
                        .setToken(new Token(token, tokenTimestamp))
                        .build();
centrifugo.connect();
Subscribe to channel:
String channel = "my-channel";
centrifugo.subscribe(new SubscriptionRequest(channel));
Listen to events:
Connection events
centrifugo.setConnectionListener(new ConnectionListener() {

        @Override
        public void onWebSocketOpen() {
        }

        @Override
        public void onConnected() {
        }

        @Override
        public void onDisconnected(final int code, final String reason, final boolean remote) {
        }

});
Subscription events
centrifugo.setSubscriptionListener(new SubscriptionListener() {

        @Override
        public void onSubscribed(final String channelName) {
        }

        @Override
        public void onUnsubscribed(final String channelName) {
        }

        @Override
        public void onSubscriptionError(final String channelName, final String error) {
        }

});
Messages, published into channel
centrifugo.setDataMessageListener(new DataMessageListener() {

        @Override
        public void onNewDataMessage(final DataMessage message) {
        }

});
Join and leave events
centrifugo.setJoinLeaveListener(new JoinLeaveListener() {

        @Override
        public void onJoin(final JoinMessage joinMessage) {
            message(joinMessage.getUser(), " just joined " + joinMessage.getChannel());
        }

        @Override
        public void onLeave(final LeftMessage leftMessage) {
            message(leftMessage.getUser(), " just left " + leftMessage.getChannel());
        }

});
Request information

You can request history of the channel

centrifugo.requestHistory("my-channel")

Installation

Add

compile 'org.coindirect:centrifuge-java:0.37'

to dependencies in your build.gradle

so your build.gradle looks something like this:


repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}

...

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'org.coindirect:centrifuge-java:0.37'
}

Have a look at example application

Versions

Version
0.38