Child pages
  • A Basic Application
Skip to end of metadata
Go to start of metadata

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;

@Component
public class BuyComponent implements BuyService {

   @Producer(target="BuyChannel")
   private BuyChannel buyChannel;

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

The above producer is connected to the "BuyChannel" channel using the Producer annotation. The next excerpt subscribes to receive BuyEvents:

import org.fabric3.api.annotation.Consumer;

@Component
public class BuyListener {

   @Consumer(source="BuyChannel")
   public void onEvent(BuyEvent event) {
      ...
   }
}

Channels are configured in a composite using XML or a DSL:

In XML: 
 
<composite ...>
   <channel name="BuyChannel"/>
</composite>

 
Using the DSL:
 
package f3;

public class ChannelProvider {
    @Provides
    public static Composite testComposite() {
        QName name = new QName("urn:test", "ChannelComposite");
        ChannelDefinitionBuilder channelBuilder = ChannelDefinitionBuilder.newBuilder("BuyChannel");
        return CompositeBuilder.newBuilder(name).channel(channelBuilder.build()).build();
    }
}

For more details on using the DSL, see Annotations and the DSL.

Write a comment…