Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from AlainODea-haskell/TLS_using_connection
Add support for TLS connections (FIX #39)
- Loading branch information
Showing
5 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{-# OPTIONS -XOverloadedStrings #-} | ||
import Network.AMQP | ||
|
||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
|
||
|
||
main = do | ||
let opts = defaultConnectionOpts { | ||
coServers = [("127.0.0.1", 5671)] | ||
, coTLSSettings = Just TLSTrusted | ||
} | ||
conn <- openConnection'' opts | ||
chan <- openChannel conn | ||
|
||
|
||
--declare queues, exchanges and bindings | ||
declareQueue chan newQueue {queueName = "myQueueDE"} | ||
declareQueue chan newQueue {queueName = "myQueueEN"} | ||
|
||
declareExchange chan newExchange {exchangeName = "topicExchg", exchangeType = "topic"} | ||
bindQueue chan "myQueueDE" "topicExchg" "de.*" | ||
bindQueue chan "myQueueEN" "topicExchg" "en.*" | ||
|
||
|
||
--subscribe to the queues | ||
consumeMsgs chan "myQueueDE" Ack myCallbackDE | ||
consumeMsgs chan "myQueueEN" Ack myCallbackEN | ||
|
||
|
||
getLine -- wait for keypress | ||
closeConnection conn | ||
putStrLn "connection closed" | ||
|
||
|
||
|
||
|
||
myCallbackDE :: (Message,Envelope) -> IO () | ||
myCallbackDE (msg, env) = do | ||
putStrLn $ "received from DE: "++(BL.unpack $ msgBody msg) | ||
ackEnv env | ||
|
||
|
||
myCallbackEN :: (Message,Envelope) -> IO () | ||
myCallbackEN (msg, env) = do | ||
putStrLn $ "received from EN: "++(BL.unpack $ msgBody msg) | ||
ackEnv env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{-# OPTIONS -XOverloadedStrings #-} | ||
import Network.AMQP | ||
|
||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
|
||
|
||
main = do | ||
let opts = defaultConnectionOpts { | ||
coServers = [("127.0.0.1", 5671)] | ||
, coTLSSettings = Just TLSTrusted | ||
} | ||
conn <- openConnection'' opts | ||
chan <- openChannel conn | ||
|
||
|
||
--declare queues, exchanges and bindings | ||
declareQueue chan newQueue {queueName = "myQueueDE"} | ||
declareQueue chan newQueue {queueName = "myQueueEN"} | ||
|
||
declareExchange chan newExchange {exchangeName = "topicExchg", exchangeType = "topic"} | ||
bindQueue chan "myQueueDE" "topicExchg" "de.*" | ||
bindQueue chan "myQueueEN" "topicExchg" "en.*" | ||
|
||
--publish messages | ||
publishMsg chan "topicExchg" "de.hello" | ||
(newMsg {msgBody = (BL.pack "hallo welt"), | ||
msgDeliveryMode = Just NonPersistent} | ||
) | ||
publishMsg chan "topicExchg" "en.hello" | ||
(newMsg {msgBody = (BL.pack "hello world"), | ||
msgDeliveryMode = Just NonPersistent} | ||
) | ||
|
||
|
||
closeConnection conn |