ws

package
v0.0.0-...-97327ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

WebSocket adapter

WebSocket adapter provides an WebSocket API for sending and receiving messages through the platform.

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

Variable Description Default
MF_WS_ADAPTER_CLIENT_TLS Flag that indicates if TLS should be turned on false
MF_WS_ADAPTER_CA_CERTS Path to trusted CAs in PEM format
MF_WS_ADAPTER_LOG_LEVEL Log level for the WS Adapter error
MF_WS_ADAPTER_PORT Service WS port 8180
MF_NATS_URL NATS instance URL nats://localhost:4222
MF_THINGS_URL Things service URL localhost:8181
MF_JAEGER_URL Jaeger server URL localhost:6831
MF_WS_ADAPTER_THINGS_TIMEOUT Things gRPC request timeout in seconds 1

Deployment

The service is distributed as Docker container. The following snippet provides a compose file template that can be used to deploy the service container locally:

version: "2"
services:
  ws:
    image: mainflux/ws:[version]
    container_name: [instance name]
    ports:
      - [host machine port]:[configured port]
    environment:
      MF_THINGS_URL: [Things service URL]
      MF_NATS_URL: [NATS instance URL]
      MF_WS_ADAPTER_PORT: [Service WS port]
      MF_WS_ADAPTER_LOG_LEVEL: [WS adapter log level]
      MF_WS_ADAPTER_CLIENT_TLS: [Flag that indicates if TLS should be turned on]
      MF_WS_ADAPTER_CA_CERTS: [Path to trusted CAs in PEM format]
      MF_JAEGER_URL: [Jaeger server URL]
      MF_WS_ADAPTER_THINGS_TIMEOUT: [Things gRPC request timeout in seconds]

To start the service outside of the container, execute the following shell script:

# download the latest version of the service
go get github.com/mainflux/mainflux

cd $GOPATH/src/github.com/mainflux/mainflux

# compile the ws
make ws

# copy binary to bin
make install

# set the environment variables and run the service
MF_THINGS_URL=[Things service URL] MF_NATS_URL=[NATS instance URL] MF_WS_ADAPTER_PORT=[Service WS port] MF_WS_ADAPTER_LOG_LEVEL=[WS adapter log level] MF_WS_ADAPTER_CLIENT_TLS=[Flag that indicates if TLS should be turned on] MF_WS_ADAPTER_CA_CERTS=[Path to trusted CAs in PEM format] MF_JAEGER_URL=[Jaeger server URL] MF_WS_ADAPTER_THINGS_TIMEOUT=[Things gRPC request timeout in seconds] $GOBIN/mainflux-ws

Usage

For more information about service capabilities and its usage, please check out the WebSocket paragraph in the Getting Started guide.

Documentation

Overview

Package ws contains the domain concept definitions needed to support Mainflux ws adapter service functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFailedMessagePublish indicates that message publishing failed.
	ErrFailedMessagePublish = errors.New("failed to publish message")

	// ErrFailedSubscription indicates that client couldn't subscribe to specified channel.
	ErrFailedSubscription = errors.New("failed to subscribe to a channel")

	// ErrFailedConnection indicates that service couldn't connect to message broker.
	ErrFailedConnection = errors.New("failed to connect to message broker")
)

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Messages chan mainflux.RawMessage
	Closed   chan bool
	// contains filtered or unexported fields
}

Channel is used for receiving and sending messages.

func NewChannel

func NewChannel() *Channel

NewChannel instantiates empty channel.

func (*Channel) Close

func (channel *Channel) Close()

Close channel and stop message transfer.

func (*Channel) Send

func (channel *Channel) Send(msg mainflux.RawMessage)

Send method send message over Messages channel.

type Service

type Service interface {
	mainflux.MessagePublisher

	// Subscribes to channel with specified id.
	Subscribe(string, string, *Channel) error
}

Service specifies web socket service API.

func New

func New(pubsub Service) Service

New instantiates the WS adapter implementation.

Directories

Path Synopsis
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package nats contains NATS message publisher implementation.
Package nats contains NATS message publisher implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL