simplexmq-0.4.1: SimpleXMQ message broker
Copyright(c) simplex.chat
LicenseAGPL-3
Maintainerchat@simplex.chat
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Simplex.Messaging.Agent

Description

This module defines SMP protocol agent with SQLite persistence.

See https://github.com/simplex-chat/simplexmq/blob/master/protocol/agent-protocol.md

Synopsis

SMP agent over TCP

runSMPAgent :: (MonadRandom m, MonadUnliftIO m) => ATransport -> AgentConfig -> m () Source #

Runs an SMP agent as a TCP service using passed configuration.

See a full agent executable here: https://github.com/simplex-chat/simplexmq/blob/master/apps/smp-agent/Main.hs

runSMPAgentBlocking :: (MonadRandom m, MonadUnliftIO m) => ATransport -> TMVar Bool -> AgentConfig -> m () Source #

Runs an SMP agent as a TCP service using passed configuration with signalling.

This function uses passed TMVar to signal when the server is ready to accept TCP requests (True) and when it is disconnected from the TCP socket once the server thread is killed (False).

queue-based SMP agent

getAgentClient :: (MonadUnliftIO m, MonadReader Env m) => m AgentClient Source #

Creates an SMP agent client instance that receives commands and sends responses via TBQueues.

runAgentClient :: (MonadUnliftIO m, MonadReader Env m) => AgentClient -> m () Source #

Runs an SMP agent instance that receives commands and sends responses via TBQueues.

SMP agent functional API

type AgentMonad m = (MonadUnliftIO m, MonadReader Env m, MonadError AgentErrorType m) Source #

Agent monad with MonadReader Env and MonadError AgentErrorType

getSMPAgentClient :: (MonadRandom m, MonadUnliftIO m) => AgentConfig -> m AgentClient Source #

Creates an SMP agent client instance

createConnection :: AgentErrorMonad m => AgentClient -> m (ConnId, SMPQueueInfo) Source #

Create SMP agent connection (NEW command)

joinConnection :: AgentErrorMonad m => AgentClient -> SMPQueueInfo -> ConnInfo -> m ConnId Source #

Join SMP agent connection (JOIN command)

acceptConnection :: AgentErrorMonad m => AgentClient -> ConnId -> ConfirmationId -> ConnInfo -> m () Source #

Approve confirmation (LET command)

subscribeConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m () Source #

Subscribe to receive connection messages (SUB command)

sendMessage :: AgentErrorMonad m => AgentClient -> ConnId -> MsgBody -> m AgentMsgId Source #

Send message to the connection (SEND command)

suspendConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m () Source #

Suspend SMP agent connection (OFF command)

deleteConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m () Source #

Delete SMP agent connection (DEL command)