<commit_before>* Welcome!
  =snaplet-amqp= provides a convenience interface to the Haskell AMQP
  package.

  #+BEGIN_SRC
  {-# LANGUAGE FlexibleInstances #-}
  {-# LANGUAGE OverloadedStrings #-}
  {-# LANGUAGE RecordWildCards   #-}
  {-# LANGUAGE TemplateHaskell   #-}

  module Main where

  ------------------------------------------------------------------------------
  import           Control.Lens
  import           Data.ByteString.Char8 as C8
  import           Network.AMQP
  import           Snap
  import           Snap.Snaplet.AMQP

  ------------------------------------------------------------------------------
  data App = App
      { _amqp :: Snaplet AmqpState
      }

  makeLenses ''App

  instance HasAmqpConn (Handler b App) where
      getAmqpConn = with amqp getAmqpConn

  ------------------------------------------------------------------------------
  -- | The application's routes.
  routes :: [(ByteString, Handler App App ())]
  routes = [ ("/"   , writeText "hello")
           , ("test", fooHandler)
           ]

  fooHandler :: Handler App App ()
  fooHandler = do
      let serverQueue = "myQueue"
          exchange'   = "myExchange"
          routingKey  = "myKey"

      _ <- runAmqp $ \(_, chan) -> do
          _ <- declareQueue chan newQueue {queueName = serverQueue}

          declareExchange chan newExchange {exchangeName = exchange', exchangeType = "headers"}
          bindQueue       chan serverQueue exchange' routingKey

          -- Update all dimmers in the group with the NEW group configuration
          publishMsg chan exchange' routingKey
              newMsg {msgBody = "AMQP Snaplet!",
                      msgDeliveryMode = Just Persistent}

      modifyResponse $ setResponseCode 204


  ------------------------------------------------------------------------------
  -- | The application initializer.
  app :: SnapletInit App App
  app = makeSnaplet "app" "An snaplet example application." Nothing $ do
      m <- nestSnaplet "amqp" amqp $ initAMQP
      addRoutes routes
      return $ App m


  main :: IO ()
  main = serveSnaplet defaultConfig app
  #+END_SRC<commit_msg>Minor fix<commit_after>* Welcome!
  =snaplet-amqp= provides a convenience interface to the Haskell AMQP
  package.

  #+BEGIN_SRC
  {-# LANGUAGE FlexibleInstances #-}
  {-# LANGUAGE OverloadedStrings #-}
  {-# LANGUAGE RecordWildCards   #-}
  {-# LANGUAGE TemplateHaskell   #-}

  module Main where

  ------------------------------------------------------------------------------
  import           Control.Lens
  import           Data.ByteString.Char8 as C8
  import           Network.AMQP
  import           Snap
  import           Snap.Snaplet.AMQP

  ------------------------------------------------------------------------------
  data App = App
      { _amqp :: Snaplet AmqpState
      }

  makeLenses ''App

  instance HasAmqpConn (Handler b App) where
      getAmqpConn = with amqp getAmqpConn

  ------------------------------------------------------------------------------
  -- | The application's routes.
  routes :: [(ByteString, Handler App App ())]
  routes = [ ("/"   , writeText "hello")
           , ("test", fooHandler)
           ]

  fooHandler :: Handler App App ()
  fooHandler = do
      let serverQueue = "myQueue"
          exchange'   = "myExchange"
          routingKey  = "myKey"

      _ <- runAmqp $ \(_, chan) -> do
          _ <- declareQueue chan newQueue {queueName = serverQueue}

          declareExchange chan newExchange {exchangeName = exchange',
                                            exchangeType = "headers"}
          bindQueue       chan serverQueue exchange' routingKey

          publishMsg chan exchange' routingKey
              newMsg {msgBody = "AMQP Snaplet!",
                      msgDeliveryMode = Just Persistent}

      modifyResponse $ setResponseCode 204


  ------------------------------------------------------------------------------
  -- | The application initializer.
  app :: SnapletInit App App
  app = makeSnaplet "app" "An snaplet example application." Nothing $ do
      m <- nestSnaplet "amqp" amqp $ initAMQP
      addRoutes routes
      return $ App m

  main :: IO ()
  main = serveSnaplet defaultConfig app
  #+END_SRC
{'fraction_non_alphanumeric': 0.22138305404767525, 'fraction_numerical': 0.002360160490913382, 'mean_word_length': 1.3715724678231673, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '161788', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1052, 'n_words': 305}