MyNixOS website logo
Description

RabbitMQ Messaging API supporting request-response.

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.

Metadata

Version

0.1.2.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows