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

Version 1 Next »


Wires are used to connect clients directly to a service. Many applications, however, require support for broadcast-style interactions where clients send messages to a destination that consumers can listen on. Often referred to as "PubSub", Fabric3 supports composing these highly decoupled interactions through SCA eventing. This chapter provides an overview of how to use Fabric3's eventing facilities.
Note that as an evolving part of the SCA specifications, eventing is not complete. Therefore, while the Fabric3 implementation is robust, the specifications are subject to change. Depending on how the specifications evolve, it is possible for API and configuration changes to be introduced. While the Fabric3 implementation attempts to steer clear of implementing parts of eventing that may be subject to significant change, users should be aware that eventing is still a work in progress.

A Basic Application


Eventing-style interactions involve a component that acts as a source of events, which are dispatched to a channel. Consumer components can be 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 defined 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.
As with references, producers and channels may be configured with bindings (currently the only supported binding is JMS). This allows events to be sent across clusters. Bindings are configured in the same way as references.
If no bindings are specified and a producer is defined in a composite that is deployed to a different cluster (zone) than a channel, Fabric3 will automatically create a remote binding between the two. For example, if the BuyComponent in the previous example were deployed to a different cluster than the BuyChannel, Fabric3 will generate a remote binding to propagate messages from the producer component to the channel.
In addition to SCA Java components, Fabric3 supports injecting producers on Spring beans and timer components. Timer components are particularly useful for modeling events that are periodically generated. Fabric3 also supports configuring Spring beans as consumers.
For further examples, both the samples and Spring samples contain an eventing application.

Enabling Eventing


Eventing is a core runtime capability. Consequently, optional extensions do not need to be installed.