Giter Site home page Giter Site logo

swifty-nats's Introduction

SwiftyNats

A swift client for interacting with a nats server.

Build Status License Swift4

Installation

Only uses SPM to install. Add the dependencies like below.

// swift-tools-version:4.0

import PackageDescription

let package = Package(
    name: "YourApp",
    products: [
        .library(name: "YourApp", targets: ["YourApp"])
    ],
    dependencies: [
        .package(url: "https://github.com/raykrow/swifty-nats.git", from: "1.0.0")
    ],
    targets: [
        .target(
            name: "YourApp",
            dependencies: ["SwiftyClient"]
        ),
    ]
)

Basic Usage

import SwiftyNats

let client = NatsClient("http://nats.server:4222")

client.on(.connect) { _ in
    print("Client connected")
}

try? client.connect()

client.subscribe("foo.bar") { message in
    print("payload: \(message.payload)")
    print("size: \(message.byteCount)")
    print("reply subject: \(message.replySubject.subject)")
}

client.publish("this event happened", to: "foo.bar")

TODO

  • Save connect_urls property from INFO response and use it later when attempting to reconnect
  • In publish method make the payload optional. Its ok to send 0 count and no payload PUB swift.test 0\r\n\r\n (just pass "" as payload)
  • Support subscribing to a queue group SUB swift.test G1 11\r\n
  • Configurable max queue size, default 100
  • Configurable message encoding, default UTF-8
  • When trying to reconnect to the server, wait 5 seconds between retries, configurable
  • Add a reconnecting event

swifty-nats's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

swifty-nats's Issues

Dokumentation event handler

Hi,

found out, that is should be

client.on(.connected) { _ in
    print("Client connected")
}

instead of the event .connect like the README.md said.

Sorry, ne PR today.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.