Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #--
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. #++
  19.  
  20. require 'qpid_proton'
  21.  
  22. class HelloWorld < Qpid::Proton::Handler::MessagingHandler
  23.  
  24. def initialize(server, address)
  25. super()
  26. @server = server
  27. @address = address
  28. end
  29.  
  30. def on_start(event)
  31. puts "on_start"
  32. conn = event.container.connect(:address => @server)
  33. event.container.create_receiver(conn, @address)
  34. event.container.create_sender(conn, @address)
  35. end
  36.  
  37. def on_sendable(event)
  38. puts "on_sendable!"
  39. event.sender.send(Qpid::Proton::Message.new("Hello world!"))
  40. event.sender.close
  41. end
  42.  
  43. def on_message(event)
  44. puts "Got a message!"
  45. puts event.message.body
  46. event.connection.close
  47. end
  48. end
  49.  
  50. hw = HelloWorld.new("localhost:5672", "examples")
  51. Qpid::Proton::Reactor::Container.new(hw).run { puts "Passing..." }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement