...
Code Block | ||||
---|---|---|---|---|
| ||||
<component name="TheComponent"> <implementation.java .../> <reference name="service"> <binding.jms> <connectionFactory name="TheFactory"/> <destination name="ServiceQueue"/> </binding.jms> </reference> </component> |
Using the DSL
The following is an example provider that configures a channel with an ActiveMQ connection factory. Note the use of an environment variable - 'local' - to set the broker URL:
Code Block | ||
---|---|---|
| ||
public class ServiceCompositeProvider {
@Provides
public static Composite createComposite(@Environment String environment) {
CompositeBuilder compositeBuilder = CompositeBuilder.newBuilder(SERVICE_COMPOSITE_QNAME);
createConnectionFactory(compositeBuilder);
createChannel(compositeBuilder);
return compositeBuilder.build();
}
private static void createChannel(CompositeBuilder compositeBuilder) {
JmsBindingDefinitionBuilder bindingBuilder = JmsBindingDefinitionBuilder.newBuilder();
bindingBuilder.destination(MESSAGE_TOPIC, TOPIC);
bindingBuilder.localDelivery(true);
bindingBuilder.connectionFactoryName("ConnectionFactory");
bindingBuilder.durable(true);
bindingBuilder.cacheLevel(CacheLevel.ADMINISTERED_OBJECTS);
BindingDefinition binding = bindingBuilder.build();
ChannelDefinitionBuilder channelBuilder = ChannelDefinitionBuilder.newBuilder(MESSAGE_CHANNEL);
channelBuilder.binding(binding);
compositeBuilder.channel(channelBuilder.build());
}
private static void createConnectionFactory(CompositeBuilder compositeBuilder) {
ConnectionFactoryResourceBuilder resourceBuilder = ConnectionFactoryResourceBuilder.newBuilder("ConnectionFactory");
resourceBuilder.username("test");
resourceBuilder.password("test");
boolean isLocal = Boolean.parseBoolean(System.getProperty("local"));
if (isLocal) {
resourceBuilder.attribute("broker.uri", URI.create("tcp://localhost:61616"));
} else {
resourceBuilder.attribute("broker.uri", URI.create("ssl://broker:61616"));
}
resourceBuilder.clientId("{runtime}");
resourceBuilder.type(ConnectionFactoryType.LOCAL);
compositeBuilder.resource(resourceBuilder.build());
}
}
|
Configuring the Embedded ActiveMQ Broker
The default configuration using by the embedded ActiveMQ broker may be overridden in systemConfig.xml to specify custom ActiveMQ network and transport connectors:
Code Block | ||||
---|---|---|---|---|
| ||||
<jms> <active.mq><activemq> <networkConnectors> <networkConnector uri="multicast://default"/> </networkConnectors> <transportConnectors> <transportConnector name="openwire" uri="tcp://localhost:61616"/> </transportConnectors> </active.mq>activemq> </jms> |
Configuring Connection Factories
...
The factory.properties
element contains a list of key/value properties that are specific to the JMS provider. Client ID is used for durable connections. If the value '{runtime}' is specified, the Fabric3 runtime name will be used.
ActiveMQ also support supports the type
attribute with LOCAL or XA as values.
...