electronic.alchemy :: Stomp
electronic.alchemy
where the past meets the future
pike > Fins > Developer > Stomp

Stomp

Created by hww3. Last updated by hww3, 10 years ago. Version #4.

Creating a Stomp-enabled application

Fins has support for sending and receiving messages via the http://stomp.github.com/ protocol. This support is broken into three parts:

  1. a processor that acts as the central coordination point for Stomp communications
  2. a controller class that you implement in order to process messages received from a destination
  3. a class that can be inherited anywhere you want to be able to publish messages
For a complete example, see the Stomper application, located in the http://hg.welliver.org/stomper

Enabling message receipt and processing

1. enable Stomp support for your Message Broker (see [external]http://stomp.codehaus.org for more details.)

2. install Public.Protocols.Stomp from monger.

  pike -x monger --install Public.Protocols.Stomp

3. add the following to your application configuration file:

[processors]
class=my_stomp_processor

[stomp] broker=stomp://user:pass@host:port

4. create a class, my_stomp_processor (as mentioned in the configuration file above) that inherits Fins.StompProcessor, saved in the classes directory of your application.

  inherit Fins.StompProcessor;

5. create a controller class that inherits Fins.StompController and overrides the constant subscribes_to. The constant subscribes_to should be a STOMP messaging destination. This example code might be called classes/my_stomp_controller.pike:

  inherit Fins.StompController;

constant subscribes_to = "/queue/my_queue";

6. mount that new StompController class within your controller tree, just as you would with any other controller. its location doesn't matter, and it makes sense to mark it static. For example, from your controller.pike:

inherit Fins.FinsController;

Fins.Controller my_stomp_controller;

void start() { my_stomp_controller = load_controller("my_stomp_controller"); }

7. implement on_message() in your Stomp controller. For example, in our my_stomp_controller.pike described above:

  inherit Fins.StompController;

constant subscribes_to = "/queue/my_queue";

void on_message(Fins.StompRequest request) { // handle the message here. werror("Headers: %On", request->headers); werror("Body: %On", request->body); }

Enabling message publishing

1. Publishing requires the StompProcessor to be enabled for your application, so if you only want to send messages, you don't need to define a StompController (steps 5-7) above.

2. Messaging works from any class derived from Fins.FinsBase, which is any Controller, the View or Model.

3. Inherit Fins.StompMessenger in the class you want to be able to send messages from.

4. To send a message, you can use the publish() method provided in Fins.StompMessenger.

  inherit Fins.StompController;
  inherit Fins.StompMessenger;

constant subscribes_to = "/queue/my_queue";

void on_message(Fins.StompRequest request) { // handle the message here. werror("Headers: %On", request->headers); werror("Body: %On", request->body); // publish() is provided by StompMessenger. publish("/topics/my_topic", "thanks for the message.", (["header1": "somevalue"])); }

Not categorized | RSS Feed | BackLinks

comments powered by Disqus