Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current Restore this Version View Page History

« Previous Version 9 Current »

Eventing-style interactions involve a component that acts as a source or producer of events which are dispatched to a channel. In turn, consumer components are configured to listen on a channel for events. Similar to reference injection, a source component is injected with a producer proxy using the Fabric3 @Producer annotation. This proxy is responsible for dispatching messages to a channel. A component subscribes to a channel using a consumer method.

The following is an example of a source component with a an injected producer:

import org.fabric3.api.annotation.Producer;

public class BuyComponent implements BuyService {

   @Producer
   private BuyChannel buyChannel;

   public void process() {
      BuyEvent event = ...
      buyChannel.publish(event);*
   }
}

The above example uses the default producer name "buyChannel". Alternatively, a name could be specified on the @Producer annotation. The next excerpt subscribes to receive BuyEvents:

import org.fabric3.api.annotation.Consumer;

public class BuyListener {

   @Consumer("buyChannel")
   public void onEvent(BuyEvent event) {
      ...
   }
}

Producers, consumers, and channels are configured in a composite:

<composite ...>

   <component name="BuyComponent">
      <implementation.java .../>
      <producer name="buyChannel" target="BuyChannel"/>
   </component>

   <component name="BuyListener">
      <implementation.java .../>
      <consumer name="buyChannel" source="BuyChannel"/>
   </component>

   <channel name="BuyChannel"/>

</composite>

In this example, the producer, consumer, and channel are configured in a single composite. In many applications, these may be defined in different composites. For example, a composite may only contain channel definitions, while others contain definitions for producers and consumers.