Latest 0.1.3
Homepage https://github.com/seidju/RxSTOMP
License MIT
Platforms ios 10.0, requires ARC
Dependencies CocoaAsyncSocket, RxSwift
Frameworks Foundation
Authors

MIT licensed
[CocoaPods]()
Swift
iOS

alt_text

RxSTOMP is a variation of STOMP client, written in Swift3, using RxSwift and CocoaAsyncSocket.

Installation

Quickly install using CocoaPods:

pod 'RxSTOMP'

Or manually install:

  1. Clone this repository
  2. Copy Core folder to your project
  3. Don’t forget to install RxSwift dependency
  4. Profit

There’s also Example with simple usage how-to.

How to use

First of all don’t forget to configure host and port of your STOMP server:

  RxSTOMPConfiguration.Network.host = "example.com"
  RxSTOMPConfiguration.Network.port = 7691

RxSTOMPConfiguration is a struct, where defined a lot of parameters, such as Read&Write timeouts, Tags, Queues, Host configuration

Then you need to initialize RxSTOMPStream object, which is responsible for handling socket connection and everything.
You can do it either just init with default initializer:

let rxStompStream = RxSTOMPStream()

Or using DI, for example Swinject:

   let container = Container() { container in        
        // Models
        container.register(RxSTOMPStreamProtocol.self) { _ in RxSTOMPStream() }

        // Views
        container.storyboardInitCompleted(ExampleViewController.self) {r,c in
            c.viewModel = r.resolve(ExampleViewModel.self)!
        }

        //View models
        container.register(ExampleViewModel.self) { r
            in ExampleViewModel(stompStream: r.resolve(RxSTOMPStreamProtocol.self)!)
        }
    }

Then after you connect, you just subscribe to two types of events: state and incoming frames:

self.rxStompStream.connect()

func subscribeToState() {
    self.rxStompStream.state
    .observeOn(SerialDispatchQueueScheduler(queue: RxSTOMPConfiguration.Queue.stompQueue, internalSerialQueueName: "stomp"))
    .filter { $0 == .connected } //after we connected -> do some stuff
    .subscribe(onNext: {[weak self] _ in
        guard let sSelf = self else { return }
        guard let login = sSelf.login, let passcode = sSelf.passcode else { return }
        sSelf.rxStompStream.auth(login: login, passcode: passcode)
    }).addDisposableTo(disposeBag)
}

//subscribe to incoming messages, like CONNECT, DISCONNECT, MESSAGE and etc...
 func subscribeToFrames() {
    self.rxStompStream.inputFrame
    .observeOn(SerialDispatchQueueScheduler(queue: RxSTOMPConfiguration.Queue.stompQueue, internalSerialQueueName: "stomp"))
    .subscribe(onNext: { inputFrame in
       print("input frame: (inputFrame)")
    }).addDisposableTo(disposeBag)
}    

Latest podspec

{
    "name": "RxSTOMP",
    "platforms": {
        "ios": "10.0"
    },
    "summary": "Simple implementation of STOMP protocol via CocoaAsyncSocket and RxSwift",
    "requires_arc": true,
    "version": "0.1.3",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Pavel Shatalov": "[email protected]"
    },
    "homepage": "https://github.com/seidju/RxSTOMP",
    "source": {
        "git": "https://github.com/seidju/RxSTOMP.git",
        "tag": "0.1.3"
    },
    "frameworks": "Foundation",
    "dependencies": {
        "CocoaAsyncSocket": [],
        "RxSwift": []
    },
    "source_files": "RxSTOMP/**/*.{swift}",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This