• Stars
    star
    570
  • Rank 78,245 (Top 2 %)
  • Language
    Java
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

STOMP protocol via WebSocket for Android

STOMP protocol via WebSocket for Android

Release

Overview

This library provide support for STOMP protocol https://stomp.github.io/ At now library works only as client for backend with support STOMP, such as NodeJS (stompjs or other) or Spring Boot (SockJS).

Add library as gradle dependency

repositories { 
    jcenter()
    maven { url "https://jitpack.io" }
}
dependencies {
    implementation 'com.github.NaikSoftware:StompProtocolAndroid:{latest version}'
}

Example backend (Spring Boot)

WebSocketConfig.groovy

@Configuration
@EnableWebSocket
@EnableWebSocketMessageBroker
class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic", "/queue", "/exchange");
//        config.enableStompBrokerRelay("/topic", "/queue", "/exchange"); // Uncomment for external message broker (ActiveMQ, RabbitMQ)
        config.setApplicationDestinationPrefixes("/topic", "/queue"); // prefix in client queries
        config.setUserDestinationPrefix("/user");
    }

    @Override
    void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/example-endpoint").withSockJS()
    }
}

SocketController.groovy

@Slf4j
@RestController
class SocketController {

    @MessageMapping('/hello-msg-mapping')
    @SendTo('/topic/greetings')
    EchoModel echoMessageMapping(String message) {
        log.debug("React to hello-msg-mapping")
        return new EchoModel(message.trim())
    }
}

Check out the full example server https://github.com/NaikSoftware/stomp-protocol-example-server

Example library usage

Basic usage

 private StompClient mStompClient;
 
 // ...
 
 mStompClient = Stomp.over(Stomp.ConnectionProvider.OKHTTP, "ws://10.0.2.2:8080/example-endpoint/websocket");
 mStompClient.connect();
  
 mStompClient.topic("/topic/greetings").subscribe(topicMessage -> {
     Log.d(TAG, topicMessage.getPayload());
 });
  
 mStompClient.send("/topic/hello-msg-mapping", "My first STOMP message!").subscribe();
  
 // ...
 
 mStompClient.disconnect();

See the full example https://github.com/NaikSoftware/StompProtocolAndroid/tree/master/example-client

Method Stomp.over consume class for create connection as first parameter. You must provide dependency for lib and pass class. At now supported connection providers:

  • org.java_websocket.WebSocket.class ('org.java-websocket:Java-WebSocket:1.3.0')
  • okhttp3.WebSocket.class ('com.squareup.okhttp3:okhttp:3.8.0')

You can add own connection provider. Just implement interface ConnectionProvider. If you implement new provider, please create pull request :)

Subscribe lifecycle connection

mStompClient.lifecycle().subscribe(lifecycleEvent -> {
    switch (lifecycleEvent.getType()) {
    
        case OPENED:
            Log.d(TAG, "Stomp connection opened");
            break;
            
        case ERROR:
            Log.e(TAG, "Error", lifecycleEvent.getException());
            break;
            
        case CLOSED:
             Log.d(TAG, "Stomp connection closed");
             break;
    }
});

Library support just send & receive messages. ACK messages, transactions not implemented yet.

More Repositories

1

J2meLoader

Application on Android for run J2ME application
Java
40
star
2

PHPRunner

Android PHP IDE
Java
19
star
3

stomp-protocol-example-server

Example server for https://github.com/NaikSoftware/StompProtocolAndroid/tree/master/example-client
Groovy
11
star
4

BluWar

2D MIDP 2.x game via bluetooth
Java
6
star
5

OnboardingTooltips

Onboarding tooltips library for Android (API 19+)
Kotlin
4
star
6

CollapsingToolbarWithImageAndTabs

Java
3
star
7

SimpleTanks

Simple game with multiplayer vie local network (such as WiFi) on Android
HTML
3
star
8

FoodAlternate

JavaScript
2
star
9

CamDiscover

Java
2
star
10

TestJmDNS

Java
2
star
11

SaveUA

Java
2
star
12

ThreeDotsProgressView

Java
2
star
13

ArityMOD

Incredible calculator for Android
Java
2
star
14

RedExpFitness

Java
2
star
15

EVGen

Personal data generator
Kotlin
2
star
16

EofCMS

New mobile CMS (content management system on PHP
PHP
2
star
17

WarOnline

Пошаговая военная стратегия для игры на Android-устройстве вдвоем или втроем. Поддержка игры по Internet.
Java
2
star
18

resource_repository

Implementation of a resource/repository pattern for data management in Flutter apps.
Dart
1
star
19

MyAlternatePortal

JavaScript
1
star
20

University-Labs

Java
1
star
21

PickWay

App for tracking you traveling
1
star
22

LogicCalc

Minimize boolean functions
C++
1
star
23

VoiceMessenger

Voice messenger over local network
HTML
1
star
24

StickyHeadersAndroid

Sticky headers for RecyclerView (Android)
Java
1
star
25

resource_repository_storage

Base classes for implementing storage for resource_repository dart package.
Dart
1
star
26

NaikSoftware.github.io

HTML
1
star
27

Blitzkrieg

This is a reversed sources for game "Blitzkrieg II" ( http://rugame.mobi/game/1663/ )
Java
1
star
28

Chars

Chars - engine for simple games a la Snake.
Java
1
star
29

NaikSoftware-Lib-Android

Additional components for android
Java
1
star
30

GraphPaths

GraphPaths - калькулятор графов. Умеет искать кратчайшие пути методами Шимбелла, Дейкстры. Решение "задачи коммивояжера" методом ветвей и границ
Java
1
star