stomp_dart_client 1.0.3 stomp_dart_client: ^1.0.3 copied to clipboard
Dart STOMP client for easy messaging interoperability. Build with flutter in mind, but should work for every dart application.
import 'dart:async';
import 'dart:convert';
import 'package:stomp_dart_client/stomp.dart';
import 'package:stomp_dart_client/stomp_config.dart';
import 'package:stomp_dart_client/stomp_frame.dart';
void onConnect(StompFrame frame) {
stompClient.subscribe(
destination: '/topic/test/subscription',
callback: (frame) {
List<dynamic>? result = json.decode(frame.body!);
print(result);
},
);
Timer.periodic(const Duration(seconds: 10), (_) {
stompClient.send(
destination: '/app/test/endpoints',
body: json.encode({'a': 123}),
);
});
}
final stompClient = StompClient(
config: StompConfig(
url: 'ws://localhost:8080',
onConnect: onConnect,
beforeConnect: () async {
print('waiting to connect...');
await Future.delayed(const Duration(milliseconds: 200));
print('connecting...');
},
onWebSocketError: (dynamic error) => print(error.toString()),
stompConnectHeaders: {'Authorization': 'Bearer yourToken'},
webSocketConnectHeaders: {'Authorization': 'Bearer yourToken'},
),
);
void main() {
stompClient.activate();
}