Skip to content

Latest commit

 

History

History
74 lines (53 loc) · 2.35 KB

README.md

File metadata and controls

74 lines (53 loc) · 2.35 KB

Stompie

If you're planning to stomp all over some sockets this little angularity to deal with STOMP queues is just the thing for you. On the big iron, server side, we're using Spring.

Getting started

  1. If you're using bower just install:
bower install -save stompie
  1. OK I know it's obvious but add <script> tags to the module and the two required dependencies:
<script src="/bower_components/sockjs/sockjs.min.js"></script>
<script src="/bower_components/stomp-websocket/lib/stomp.min.js"></script>
<script src="/bower_components/stompie/stompie-min.js"></script>
  1. Declare the module as a dependency in your application:
angular.module('yourApplication', ['stompie']);
  1. Inject it in your controller:
angular.module('yourApplication')
    .controller('YourCtrl', ['$stompie', '$scope', function ($stompie, $scope) {
        // ...
    }
  1. Use and subscribe:
$stompie.using('/your/stomp/endpoint', function () {

    // The $scope bindings are updated for you so no need to $scope.$apply.
    // The subscription object is returned by the method.
    var subscription = $stompie.subscribe('/your/topic', function (data) {
        $scope.foo = data;
    });

    // Unsubscribe using said subscription object.
    subscription.unsubscribe();

    // Send messages to a STOMP broker.
    $stompie.send('/some/queue', {message: 'some message'});

    // Disconnect from the socket.
    $stompie.disconnect(function () {
        // Called once you're out...
    });

});

Helpful information

  • You can call $stompie.using() as many times as you want, it will reuse the same socket connection.
  • The underlying libraries also mean that you can register multiple subscribers.
  • The $stompie.subscribe() callback will attempt to parse the response.
  • Objects you pass to $stompie.send() will be stringified.

Bedtime reading:

For everything else, there's MasterCard.