packages feed

amqp 0.19.1 → 0.20.0

raw patch · 4 files changed

+32/−11 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Network/AMQP.hs view
@@ -691,21 +691,31 @@ -- | Any of these fields may be empty and will be replaced with defaults from @amqp://guest:guest@localhost:5672/@
 fromURI :: String -> ConnectionOpts
 fromURI uri = defaultConnectionOpts {
-    coServers = [(host,fromIntegral nport)],
-    coVHost = (T.pack vhost),
-    coAuth = [plain (T.pack uid) (T.pack pw)]
+    coServers     = hostPorts',
+    coVHost       = (T.pack vhost),
+    coAuth        = [plain (T.pack uid) (T.pack pw)],
+    coTLSSettings = if tls then Just TLSTrusted else Nothing
   }
-  where (host,nport,uid,pw,vhost) = fromURI' uri
+  where (hostPorts, uid, pw, vhost, tls) = fromURI' uri
+        hostPorts' = [(h, fromIntegral p) | (h, p) <- hostPorts]
 
-fromURI' :: String -> (String,Int,String,String,String)
-fromURI' uri = (unEscapeString host, nport, unEscapeString (dropWhile (=='/') uid), unEscapeString pw, unEscapeString vhost)
+fromURI' :: String -> ([(String, Int)], String, String, String, Bool)
+fromURI' uri = (fromHostPort dport <$> hstPorts,
+    unEscapeString (dropWhile (=='/') uid), unEscapeString pw,
+    unEscapeString vhost, tls)
   where (pre :suf  :    _) = splitOn "@" (uri ++ "@" ) -- look mom, no regexp dependencies
         (pro :uid' :pw':_) = splitOn ":" (pre ++ "::")
         (hnp :thost:    _) = splitOn "/" (suf ++ "/" )
-        (hst':port :    _) = splitOn ":" (hnp ++ ":" )
+        hstPorts           = splitOn "," hnp
         vhost = if null thost     then "/"     else thost
         dport = if pro == "amqps" then 5671    else 5672
-        nport = if null port      then dport   else read port
         uid   = if null uid'      then "guest" else uid'
         pw    = if null pw'       then "guest" else pw'
-        host  = if null hst'      then "localhost" else hst'
+        tls   = pro == "amqps"
+
+fromHostPort :: Int -> String -> (String, Int)
+fromHostPort dport hostPort = (unEscapeString host, nport)
+    where
+        (hst':port :    _) = splitOn ":" (hostPort ++ ":" )
+        host  = if null hst' then "localhost" else hst'
+        nport = if null port then dport       else read port
amqp.cabal view
@@ -1,5 +1,5 @@ Name:                amqp
-Version:             0.19.1
+Version:             0.20.0
 Synopsis:            Client library for AMQP servers (currently only RabbitMQ)
 Description:         Client library for AMQP servers (currently only RabbitMQ)
 License:             BSD3
@@ -11,12 +11,13 @@ Build-Type:          Simple
 Homepage:            https://github.com/hreinhardt/amqp
 bug-reports:         https://github.com/hreinhardt/amqp/issues
-Cabal-Version:       >=1.8
+Cabal-Version:       >=1.10
 Extra-source-files:  examples/ExampleConsumer.hs,
                      examples/ExampleProducer.hs,
                      changelog.md
 
 Library
+  default-language: Haskell2010
   Build-Depends:
     base >= 4 && < 5,
     binary >= 0.5,
@@ -39,6 +40,7 @@   GHC-Options:        -Wall
 
 Executable amqp-builder
+  default-language: Haskell2010
   Build-Depends:      base >= 4 && < 5, xml == 1.3.*, containers >= 0.2
   Hs-Source-Dirs:     Tools
   Main-is:            Builder.hs
@@ -49,6 +51,7 @@   location: https://github.com/hreinhardt/amqp
 
 test-suite spec
+  default-language: Haskell2010
   type:
       exitcode-stdio-1.0
   ghc-options:
changelog.md view
@@ -1,3 +1,8 @@+### Version 0.20.0
+
+* `fromURI` now activates TLS if the URI starts with `ampqs://`. Previously it only changed the port, without activating TLS.
+* `fromURI` now supports multi-broker URIs in the form of `amqp://user:pass@host-1:port-2,host-2:port-2/vhost`
+
 ### Version 0.19.1
 
 * add `nackMsg` and `nackEnv` methods
test/Runner.hs view
@@ -2,6 +2,7 @@ 
 import qualified ConnectionSpec
 import qualified ChannelSpec
+import qualified FromURISpec
 import qualified QueueDeclareSpec
 import qualified QueueDeleteSpec
 import qualified QueuePurgeSpec
@@ -21,6 +22,8 @@     describe "ExchangeDeclareSpec" ExchangeDeclareSpec.spec
     -- exchange.delete
     describe "ExchangeDeleteSpec"  ExchangeDeleteSpec.spec
+    -- fromuri.*
+    describe "FromURISpec"         FromURISpec.spec
     -- queue.declare
     describe "QueueDeclareSpec"    QueueDeclareSpec.spec
     -- queue.delete