Prepare the sample
Reuse the sample from .
In , in order to use the Service Locator, you needed to add a LocatorFeature. This time, you need to add "org.talend.esb.sam.agent.feature.EventFeature".
To do this, use a Spring configuration. The simplest way is to copy the "beans.xml" from examples/talend/tesb/sam/sam-example-osgi to src/main/resources/META-INF/spring/beans.xml of this project. Below are the main contents:
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/tesb/agent-context.xml"/>
<context:annotation-config/>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="location" value="classpath:agent.properties"/>
</bean>
<bean id="eventFeature" class="org.talend.esb.sam.agent.feature.EventFeature">
<property name="mapper" ref="eventMapper"/>
<property name="eventSender" ref="eventCollector"/>
<property name="logMessageContent" value="${log.messageContent}"/>
</bean>
<bean id="eventMapper"
class="org.talend.esb.sam.agent.eventproducer.MessageToEventMapperImpl">
<property name="maxContentLength" value="${log.maxContentLength}"/>
</bean>
<bean id="eventCollector"
class="org.talend.esb.sam.agent.collector.EventCollectorImpl" >
<!-- Default interval for scheduler. Start every X millis a new scheduler -->
<property name="defaultInterval" value="${collector.scheduler.interval}"/>
<!-- Number of events within one service call. This is a maximum number.
If there are events in the queue, the events will be processed. -->
<property name="eventsPerMessageCall" value="${collector.maxEventsPerCall}"/>
<property name="monitoringServiceClient" ref="monitoringServceV1Wrapper"/>
<property name="executor" ref="defaultExecutor"/>
<property name="scheduler" ref="defaultScheduler"/>
</bean>
<bean id="memoryQueue" class="java.util.concurrent.ConcurrentLinkedQueue"/>
<task:scheduler id="defaultScheduler" pool-size="2"/>
<task:executor id="defaultExecutor" pool-size="10"/>
<bean id="monitoringServceV1Wrapper"
class="org.talend.esb.sam.agent.serviceclient.MonitoringServiceWrapper">
<property name="monitoringService" ref="monitoringServiceV1Client"/>
<!-- Number of retries Default: 5 -->
<property name="numberOfRetries" value="${service.retry.number}"/>
<!-- Delay in milliseconds between the next attemp to send.
Thread is blocked during this time. Default: 1000 -->
<property name="delayBetweenRetry" value="${service.retry.delay}"/>
</bean>
<bean id="fixedProperties"
class="org.talend.esb.sam.common.handler.impl.CustomInfoHandler">
<property name="customInfo">
<map>
<entry key="Application name" value="Service2"/>
</map>
</property>
</bean>
<jaxws:client id="customerService" address="/CustomerServicePort"
implementor="com.example.customerservice.CustomerServiceImpl">
<jaxws:features>
<ref bean="eventFeature"/>
</jaxws:features>
</jaxws:client>
And you also need to give an agent.properties file used to configure sam-agent:
collector.scheduler.interval=500
collector.maxEventsPerCall=10
log.messageContent=true
log.maxContentLength=-1
service.url=http://localhost:8040/services/MonitoringServiceSOAP
service.retry.number=3
service.retry.delay=5000
You can give a logging.properties file for logger:
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
# Set the default logging level for the root logger
.level = INFO
# Set the default logging level for new ConsoleHandler instances
java.util.logging.ConsoleHandler.level = INFO
# Set the default logging level for new FileHandler instances
java.util.logging.FileHandler.level = ALL
# Set the default formatter for new ConsoleHandler instances
#java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.formatter = //
org.sopera.monitoring.util.CustomLogFormatter
# Set the default logging level for the logger named com.mycompany
#org.talend.esb.sam.level = FINE
#org.eclipse.persistence.level = INFO
org.talend.esb.sam.level = FINE
org.eclipse.persistence.level = WARNING
You also need to change pom.xml to add more dependencies and plugins:
Add a dependency for sam-agent:
<dependency>
<groupId>org.talend.esb</groupId>
<artifactId>sam-agent</artifactId>
<version></version>
</dependency>
Change the configuration of maven-bundle-plugin as following:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.7</version>
<configuration>
<instructions>
<Bundle-SymbolicName>
${pom.groupId}.${pom.artifactId}
</Bundle-SymbolicName>
<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Version>${pom.version}</Bundle-Version>
<Export-Package>
com.example.customerservice
</Export-Package>
<Bundle-Activator>
com.example.customerservice.Activator
</Bundle-Activator>
<Require-Bundle>
org.apache.cxf.bundle;version="",
org.apache.cxf.bundle,
org.springframework.beans,
org.springframework.context,
sam-agent
</Require-Bundle>
</instructions>
</configuration>
</plugin>
Now the project structure is:
The configuration is finished, now install and deploy it into the OSGi Container, as described in previous chapters.