# HG changeset patch # User Zach Smith # Date 1557957183 25200 # Node ID 7d977f308c759491a7700db6e5de7eab28df2514 # Parent e34aabaefe44ce098a9a97358652dacac656ad09 Incorporate a series of patches from Zack Smith. - Allow a vhosts to not require a slash (use %2F in the URI, ignore literal '/') - Support setting a custom 'id' subscription diff -r e34aabaefe44 -r 7d977f308c75 src/stomp.nim --- a/src/stomp.nim Mon Oct 08 12:50:06 2018 -0700 +++ b/src/stomp.nim Wed May 15 14:53:03 2019 -0700 @@ -281,14 +281,19 @@ ## sslContext.wrapSocket(socket) ## var stomp = newStompClient( socket, "stomp+ssl://test:test@example.com/%2Fvhost" ) ## + + let + uri = parse_uri( uri ) + vhost = if uri.path.len > 1: uri.path.strip( chars = {'/'}, trailing = false ) else: uri.path + new( result ) result.socket = s result.connected = false - result.uri = parse_uri( uri ) - result.username = result.uri.username - result.password = result.uri.password - result.host = result.uri.hostname - result.vhost = result.uri.path + result.uri = uri + result.username = uri.username + result.password = uri.password + result.host = uri.hostname + result.vhost = vhost result.timeout = 500 result.subscriptions = @[] result.transactions = @[] @@ -455,7 +460,8 @@ proc subscribe*( c: StompClient, destination: string, ack = "auto", - headers: seq[ tuple[name: string, value: string] ] = @[] ): void = + id: string = "", + headers: seq[ tuple[name: string, value: string] ] = @[] ): void = ## Subscribe to messages at **destination**. ## ## Setting **ack** to "client" or "client-individual" enables client ACK/NACK mode. @@ -468,7 +474,12 @@ if not c.connected: raise newException( StompError, "Client is not connected." ) c.socksend( "SUBSCRIBE" & CRLF ) c.socksend( "destination:" & destination & CRLF ) - c.socksend( "id:" & $c.subscriptions.len & CRLF ) + + if id == "": + c.socksend( "id:" & $c.subscriptions.len & CRLF ) + else: + c.socksend( "id:" & id & CRLF ) + if ack == "client" or ack == "client-individual": c.socksend( "ack:" & ack & CRLF ) else: @@ -659,14 +670,14 @@ # ./stomp publisher [stomp-uri] [publish-destination] # # An example with an AMQP "direct" exchange, and an exclusive queue: -# ./stomp publisher stomp://test:test@localhost/?heartbeat=10 /exchange/test -# ./stomp receiver stomp://test:test@localhost/?heartbeat=10 /exchange/test +# ./stomp publisher stomp://test:test@localhost/%2F?heartbeat=10 /exchange/test +# ./stomp receiver stomp://test:test@localhost/%2F?heartbeat=10 /exchange/test # # Then just let 'er run. # -# You can also run a nieve benchmark (deliveries/sec): +# You can also run a naive benchmark (deliveries/sec): # -# ./stomp benchmark stomp://test:test@localhost/ /exchange/test +# ./stomp benchmark stomp://test:test@localhost%2F /exchange/test # # It will set messages to require acknowledgement, and nack everything, causing # a delivery loop for 10 seconds. @@ -685,17 +696,18 @@ ./stomp publisher [stomp-uri] [publish-destination] An example with an AMQP "direct" exchange, and an exclusive queue: - ./stomp publisher stomp://test:test@localhost/?heartbeat=10 /exchange/test - ./stomp receiver stomp://test:test@localhost/?heartbeat=10 /exchange/test + ./stomp publisher stomp://test:test@localhost/%2F?heartbeat=10 /exchange/test + ./stomp receiver stomp://test:test@localhost/%2F?heartbeat=10 /exchange/test Then just let 'er run. -You can also run a nieve benchmark (deliveries/sec): +You can also run a naive benchmark (deliveries/sec): - ./stomp benchmark stomp://test:test@localhost/ /exchange/test + ./stomp benchmark stomp://test:test@localhost/%2F /exchange/test It will set messages to require acknowledgement, and nack everything, causing a delivery loop for 10 seconds. +If your vhost requires slashes, use URI escaping: /%2Ftest """