freddy: RabbitMQ Messaging API supporting request-response

[ library, mit, network ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.2.0
Dependencies amqp (>=0.13.1), base (>=4.8 && <5), broadcast-chan (>=0.1.0), bytestring (>=0.9), data-default (>=0.6.0), random (>=1.1), text (>=0.11.2), uuid (>=1.3.11) [details]
License MIT
Author Indrek Juhkam
Maintainer indrek@urgas.eu
Category Network
Home page https://github.com/salemove/freddy-hs
Source repo head: git clone https://github.com/salemove/freddy-hs
Uploaded by indrek at 2016-10-08T22:10:32Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 2024 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-11-15 [all 1 reports]

Readme for freddy-0.1.2.0

[back to package description]

RabbitMQ Messaging API supporting request-response

Build Status Code Climate

Setup

  • Create a connection:
import qualified Network.Freddy as Freddy
import qualified Network.Freddy.Request as R

connection <- Freddy.connect "127.0.0.1" "/" "guest" "guest"

Delivering messages

Simple delivery

Send and forget

Sends a message to the given destination. If there is no consumer then the message stays in the queue until somebody consumes it.

  Freddy.deliver connection R.newReq {
    R.queueName = "notifications.user_signed_in",
    R.body = "{\"user_id\": 1}"
  }

Expiring messages

Sends a message to the given destination. If nobody consumes the message in timeoutInMs milliseconds then the message is discarded. This is useful for showing notifications that must happen in a certain timeframe but guaranteed delivery is not a strict requirement.

  Freddy.deliver connection R.newReq {
    R.queueName = "notifications.user_signed_in",
    R.body = "{\"user_id\": 1}",
    R.timeoutIsMs = 5000
  }

Request delivery

Sends a message to the given destination. Has a default timeout of 3 seconds and discards the message from the queue if a response hasn't been returned in that time.

  response <- Freddy.deliverWithResponse connection R.newReq {
    R.queueName = "echo",
    R.body = "{\"msg\": \"what did you say?\"}"
  }

  case response of
    Right payload -> putStrLn "Received positive result"
    Left (Freddy.InvalidRequest payload) -> putStrLn "Received error"
    Left Freddy.TimeoutError -> putStrLn "Request timed out"

Responding to messages

  processMessage (Freddy.Delivery body replyWith failWith) = replyWith body

  connection <- Freddy.connect "127.0.0.1" "/" "guest" "guest"
  Freddy.respondTo connection "echo" processMessage

Tapping into messages

Listens for messages on a given destination or destinations without consuming them.

  processMessage body = putStrLn body

  connection <- Freddy.connect "127.0.0.1" "/" "guest" "guest"
  Freddy.tapInto connection "notifications.*" processMessage
  • Note that it is not possible to respond to the message while tapping.
  • When tapping the following wildcards are supported in the queueName:
    • # matching 0 or more words
    • * matching exactly one word

Examples:

Freddy.tapInto connection "i.#.free" processMessage

receives messages that are delivered to "i.want.to.break.free"

Freddy.tapInto connection "somebody.*.love" processMessage

receives messages that are delivered to somebody.to.love but doesn't receive messages delivered to someboy.not.to.love