Popularity
8.4
Growing
Activity
0.0
Stable
3
29
0

Monthly Downloads: 5
Programming language: Haskell
License: MIT License
Tags: Network    

freddy alternatives and similar packages

Based on the "Networking" category.
Alternatively, view freddy alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of freddy or a related project?

Add another 'Networking' Package

README

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