Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The FEJ routing server provides the ability to integrate custom 3rd-party transports and use them for routing messages. For such a goalTo this purpose, the server provides few several interfaces for implementationsimplementation:

Endpoint is a basic interface that represents an instance of some entry , which could that can be uniquely identified by the routing engine for receiving or delivering messages. EndpointParams provides the unique ID of that endpoint and other additional attributes , which that may be useful for the routing logic.

Code Block
languagejava
public interface Endpoint {
    EndpointParams getParams();
}

...

It offers the ability to register listeners of of the SourceMessageListener type for processing incoming messages from external systems.

...

The DestinationEndpoint interface represents a target of the routing rules. It allows you to pass the routed message to a certain system.

...

There is also a mechanism for registering such sources like these and destinations into the server. After registration, these endpoints will be accessible for to the routing engine. Registration The registrations of sources and destinations are independent. It This means that you can register the source and the destination endpoint with the same ID. This is especially important for bidirectional transports like FIX, where in and out connections are identified by the same parameters. For such transports , like this the BidirectionalEndpoint interface exists.

...

Both of them are implemented by the EndpointRegistryAdapter class. It is available for accessing accessible via the Spring config:

Code Block
languagexml
<bean id="endpointRegistry" class="com.epam.fej.routing.endpoint.EndpointRegistryAdapter"
         c:destinationsRegister-ref="destinationsRegister"/>

...

The Transport adapter API supports the extension of the following transport implementations:

...

JMS endpoint

The JMS endpoint is the implementation of the Transport transport adapter.

There are several ways to add JMS connectivity into the FEJ container. The fej-jms.xml configuration file already contains the basic configuration for the JMS adapter:

...

The jms-adaptor.properties file contains parameters for JMS producers and consumers (FIXAJ JMS Adapter properties). The jmsConfigRegister bean (com.epam.fej.jms.DefaultJmsConfigsRegister) is responsible for loading JMS session contexts (SessionContext) from the configuration file and registering them with jmsAdaptorManager (com.epam.fej.jms.JmsAdaptorManager) for the routing engine. JmsAdaptorManager builds source and destination endpoints endpoint adapters from the given SessionContext objects and register registers them on the server.

Info

If you want use your own Configuration Factory, you can use JmsManager implementation for building and registering SessionContext instances as well.

DefaultJmsConfigsRegister produces SessionContext via the JmsContextFactory implementation. By default, it uses the com.epam.fej.jms.JndiJmsSessionContextFactory implementation but you can set you own implementation via DefaultJmsConfigsRegister.setJmsContextFactory(JmsContextFactory jmsContextFactory). Also you You can also use com.epam.fej.jms.SimpleJmsContextFactory with your definition of javax.jms.ConnectionFactory.

Code Block
languagejava
public SessionContext createSessionContext(JmsConfig config) {
    final ConnectionInfo connectionInfo = config.getConnectionInfo();
    final SessionInfo sessionInfo = config.getSessionInfo();
    return new SessionContext(connectionInfo, sessionInfo, null, jmsContextFactory.createContext(config));
}
Info

Please note that the ConnectionInfo and SessionInfo classes support the loading of custom properties from configuration files:

Code Block
languagejava
final Properties additionalProperties = connectionInfo.getAdditionalProperties();

final Map<String, Object> additionalParams = sessionInfo.getAdditionalParams();

...

The custom JMS connection factory could can be used in few several ways:

  1. Declare ConnectionFactory in Spring and inject it in SimpleJmsContextFactory:

    Code Block
    languagexml
    <bean id="jmsConfigRegister" class="com.epam.fej.jms.DefaultJmsConfigsRegister"
          p:jmsManager-ref="jmsAdaptorManager"
          p:jmsContextFactory-ref="jmsContextFactory"
          c:config-ref="jmsConfig" init-method="init"/>
    
    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
          c:brokerURL-ref="${jms.broker.url}"/>
    
    <bean id="jmsContextFactory" class="com.epam.fej.jms.SimpleJmsContextFactory"
          c:connectionFactory-ref="jmsConnectionFactory"/>
  2. Implement your own JmsContextFactory and pass it as a parameter for DefaultJmsConfigRegister:

    Code Block
    languagejava
    public class ActiveMqJmsContextFactory implements JmsContextFactory {
        @Override
        public JMSContext createContext(JmsConfig config) {
            return new SimpleJmsContext(new ActiveMQConnectionFactory(
                    config.getConnectionInfo().getProviderURL()), config.getConnectionInfo());
        }
    }
    Code Block
    languagexml
    <bean id="activeMqContextFactory" class="com.epam.fej.jms.ActiveMqJmsContextFactory"/>
    
    <bean id="jmsConfigRegister" class="com.epam.fej.jms.DefaultJmsConfigsRegister"
          p:jmsManager-ref="jmsAdaptorManager"
          p:jmsContextFactory-ref="activeMqContextFactory"
          c:config-ref="jmsConfig" init-method="init"/>

Kafka endpoint

The Kafka endpoint is a FEJ transport adapter , which that provides connectivity to the Kafka streaming platform. Its implementation is based on the FIX Antenna Java Kafka adapter and it uses the Kafka Producer and Consumer API internally.
Inside the FIXEdge Java server, each instance of the Kafka producer is represented as a destination endpoint and each instance of the consumer - is represented as a source endpoint. After the server's start, they are available for using them use in the routing rules, to accept messages from topics, and to send them to Kafka.

...

There are several ways to add Kafka connectivity into the FIXEdge/J container. The fej-kafka.xml configuration file already contains the basic configuration for the Kafka adapter:

...

The kafkaConfigRegister bean is responsible for loading Kafka session contexts (SessionContext) from the configuration file and registering them with kafkaClientManager (com.epam.fej.kafka.DefaultKafkaClientManager) for the routing engine. The kafkaClientManager bean builds source and destination endpoints endpoint adapters from the given SessionContext objects and registers them on the server.

...

Business Rules

In the case when the FIXEdge/J acts as a Producer and forwards messages to Kafka topics, please use the following business rule:

Code Block
languagegroovy
titlerules.groovy
[
	rule("Route NewOrder to Kafka")
		.sourceCondition({
		    //static filter for sesion
		    source -> source.id == "fix_client"
		})
		.condition({
			// context filter - apply this rule for New Order - Single (D) messages
			ctx -> ctx.getMessage().getTagValueAsString(35) == "D"
		})
		.action({
			// action for rule - send message to Kafka client with id 'KProducer'
			ctx ->
				routingContext.getDestinationById("KProducer").send(ctx.messageEvent)
				ctx.exit()
		})
		.build()

]


In the case when the FIXEdge/J acts as a Consumer and subscribes for to messages in Kafka topics, please use the following business rule:

...

The Camel framework is integrated into FIXEdge Java as a destination endpoint which that allows publishing messages by using the integrated components.

FIX Edge FIXEdge Java provides a definition of the Camel source endpoint ("direct:routingRule"), which can receive messages from the FIXEdge business layer. 

Please refer to the official Camel documentation for further Camel extension.

...

The JavaMail framework is integrated into FIXEdge Java as an SMTP destination endpoints and enables sending emails to external SMTP servers.

Configuration

The Spring configuration is used to config configure SMTP destination endpoints with their own properties for connection to external SMTP servers and converters to prepare automatic emails from FIX messages.

...

SMTPConfigProvider prepares SMTP configuration objects from the smtp-adaptor.properties file to use them in the SMTPAdapterManager for SMTP endpoints endpoint creation.

SMTPAdapterManager and SMTPDestinationEnpoint / SMTPMimeDestinationEndpoint configuration

SMTPAdapterManager is created as Spring Configuration Bean and on , upon its initialization, creates and registersSMTPDestinationEndpointregisters SMTPDestinationEndpoint or SMTPMimeDestinationEndpoint objects - , which are FIXEdge Java destination endpoints (for simple or MIME email messages) that can be used in routing rules to send emails to external SMTP servers.

...

  • JavaMailSender - prepared SMTP client to connect to the configured SMTP server;
  • SimpleMailMessage - prepared template with configured 'From/To/CC/BCC/Subject' values that will be common for all emails from this endpoint;
  • SimpleEmailConverter or MimeEmailConverter  - converter class with clients client logic to transform transform a MessageEvent (FIX message) to an email message (set email's text for this endpoint emails).

For the a list of the SMTP endpoint properties, refer to the Configuring SMTP endpoints section.

...

A converter class must implement either the SimpleEmailConverter or the MimeEmailConverter interfaces interface. Each interface works with different one of two email messages - : the SimpleEmailMessage (simple text without formating) or the MimeEmailMessage (message can contain HTML formatted content)

...

There are 3 possible ways to set the SMTP endpoint converter (in order to control how FEJ checks properties for it):

  • use the 'converterRef' property in SMTP configuration - define the Spring bean in FEJ config (SimpleEmailConverter or MimeEmailConverter implemented) and sets set a reference to it  (possible to define scope=prototype to have diff. instances for diff. references)
  • use the 'converterClass' property in SMTP configuration - an instance of the converter class is created when the SMTP endpoint is initialized (class SimpleEmailConverter or MimeEmailConverter implemented)
  • default converter from Spring's defaultConverterFactory (MimeEmailConverter implemented)

...

Apache Velocity Template Converters

FEJ gives support for the usage of Apache Velocity templates usage for simple Simple and MIME converters.

The Velocity engine uses objects from MessageEvent headers in its templates:

  • '$event' - in the template, this property will point to MessageEvent object
  • '$source' - in the template, this property will point to an object implemented AppEvent interface (ServerStateEvent, FIXSessionStateEvent, SnFEvent, etc)

...

Code Block
languageyml
titlemimeTemplate.vm
<b>MIME Template Test</b><br>
<i>FIX:</i> $event.getMessage()<br


Example of a rule to send that sends all FIXSessionStateEvent to SMTP destination endpoint with templates:

...