I am using WSO2 ESB with RabbitMQ, I have one proxy service and one sequence.
The proxy service works as consumer for RabbitMQ queue (via rabbitmq transport), consumed messages are send to HTTP endpoint.
The sequence works as producer to add actions in queue, calling an endpoint.
I also have an API that, for each call, inserts in the queue. Everything works correctly, but every time that we call the API, in the rabbit queue many channels are created without closing them, causing the "memory leak" problem on the Rabbit server machine.
We tried to create "direct" and "fanout" exchange, but did not resolve the memory leak problem.
Below the sequence code:
<sequence name="add-insertqueue-tostore" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint key="gov:endpoints/rabbit/insert-toqueue.xml"/>
</call>
<log level="full">
<property name="Sequence" value="AddToQueue"/>
<property name="step" value="Message inserted"/>
</log>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="false"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="false"/>
</sequence>
below the endpoint code
<endpoint name="insert-toqueue" xmlns="http://ws.apache.org/ns/synapse">
<address uri="rabbitmq:/AMQPProxy?rabbitmq.server.host.name=rabbit.server&rabbitmq.server.port=5672&rabbitmq.server.user.name=username&rabbitmq.server.password=password&rabbitmq.queue.name=queue&rabbitmq.server.virtual.host=/virtual-host&rabbitmq.exchange.name=exchange"/>
</endpoint>
below the consumer code
<proxy name="rabbit-consumer" startOnLoad="true" trace="enable" transports="rabbitmq" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property action="remove" name="SOAPAction" scope="transport"/>
<property action="remove" name="WSAction" scope="transport"/>
<property name="ContentType" scope="transport" type="STRING" value="application/json"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="HTTP_METHOD" scope="axis2" type="STRING" value="POST"/>
<property expression="json-eval($.name)" name="name" scope="default" type="STRING"/>
<property expression="json-eval($.surname)" name="surname" scope="default" type="STRING"/>
<log level="full"/>
<call-template target="my-template">
<with-param name="name" value="{get-property('name')}" xmlns:ns="http://org.apache.synapse/xsd"/>
<with-param name="surname" value="{get-property('surname')}" xmlns:ns="http://org.apache.synapse/xsd"/>
</call-template>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<parameter name="rabbitmq.exchange.type">fanout</parameter>
<parameter name="rabbitmq.exchange.name">exchange</parameter>
<parameter name="rabbitmq.queue.name">queue</parameter>
<parameter name="rabbitmq.connection.factory">AMQPConnectionFactory</parameter>
</proxy>
Do you know how to resolve this problem? thanks a lot
Did you try to reboot?
Normally it works.
Bye
When configure RabbitMQ sender maybe u can try "cached" one.
<transportSender name="rabbitmq" class="org.apache.axis2.transport.rabbitmq.RabbitMQSender">
<parameter name="CachedRabbitMQConnectionFactory" locked="false">
<parameter name="rabbitmq.server.host.name" locked="false">localhost</parameter>
<parameter name="rabbitmq.server.port" locked="false">5672</parameter>
<parameter name="rabbitmq.server.user.name" locked="false">user</parameter>
<parameter name="rabbitmq.server.password" locked="false">abc123</parameter>
</parameter>
</transportSender>
Doc link : https://docs.wso2.com/display/EI611/RabbitMQ+AMQP+Transport
Related
I am using spring integration to ftp files to a remote server and I am using xml based config. I would like to use spring cloud config , so I can move all the properties files to git and use #RefreshScope to refresh the properties. What's the best way to achieve this in spring integration which has only xmls.
I have the below code :
<bean id="inDefaultSftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="${sftp.host}" />
<property name="port" value="${sftp.port}" />
<property name="user"
value="${sftp.username}" />
<property name="password"
value="${sftp.password}" />
<property name="allowUnknownKeys" value="true" />
</bean>
Try scope="refresh" and <aop:scoped-proxy/> for that bean definition.
Something like this:
<bean id="inDefaultSftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"
scope="refresh">
<property name="host" value="${sftp.host}" />
<property name="port" value="${sftp.port}" />
<property name="user" value="${sftp.username}" />
<property name="password" value="${sftp.password}" />
<property name="allowUnknownKeys" value="true" />
<aop:scoped-proxy/>
</bean>
I am using Spring LDAP (2.0.2.RELEASE) to interact with our AD environment. I have integrated pooling within my applicationContext.xml.
In the Java LDAP docs (section 3.4), it states
If the LDAP provider cannot establish a connection within that period, it aborts the connection attempt
My question is: does spring handle a retry for this connection, or is there an error that occurs/thrown? I know Spring utilizes many of the underlying JVM LDAP features, but I have yet to find anything specific in this area.
Pertinent pieces of my applicationContext:
<bean id="dirContextValidator" class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />
<bean id="exampleConnectionDetails" class="org.springframework.ldap.core.support.LdapContextSource" scope="singleton">
<property name="url" value="ldaps://ldap.example.com:636" />
<property name="userDn" value="CN=LDAP_User,DC=example,DC=com" />
<property name="password" value="superSecretPwd" />
<property name="pooled" value="false"/>
<property name="referral" value="follow"/>
</bean>
<bean id="exampleContextSource" class="org.springframework.ldap.pool.factory.PoolingContextSource">
<property name="contextSource" ref="exampleConnectionDetails" />
<property name="dirContextValidator" ref="dirContextValidator" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="maxWait" value="10000" />
<property name="whenExhaustedAction" value="0" />
<property name="minIdle" value="5" />
<property name="maxIdle" value="10" />
<property name="timeBetweenEvictionRunsMillis" value="15000" />
<property name="minEvictableIdleTimeMillis" value="30000" />
<property name="numTestsPerEvictionRun" value="7" />
</bean>
The documentation for testOnBorrow states this,
testOnBorrow: The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and an attempt to borrow another will be made.
I understand, Spring will attempt to make another connection in the event of an failure.
We are using Spring Integration in our project and we have a requirement where If IBM MQ goes down then we will have to auto connect to IBM MQ when it is up. We have done this implementation using recoveryInterval option of org.springframework.jms.listener.DefaultMessageListenerContainer class. We have given recovery interval value to try to recover the MQ connection. But it is not recovering the connection after MQ restart. Below was my existing configuration:
<jms:message-driven-channel-adapter id="adapterId" channel="raw-channel" container="messageListenerContainer" />
<bean id="messageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="customQueueCachingConnectionFactory" />
<property name="destination" ref="requestQueue" />
<property name="recoveryInterval" value="60000" />
</bean>
Below is the Current Connection Factory :
<bean id="queueCachingConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="queueConnectionFactory" />
<property name="sessionCacheSize" value="10" />
<property name="cacheProducers" value="false" />
<!-- <property name="reconnectOnException" value="true" /> -->
<!-- <property name="exceptionListener" ref="MQExceptionListener"></property> -->
</bean>
<jee:jndi-lookup id="queueConnectionFactory" jndi-name="MQConnectionFactory"
expected-type="javax.jms.ConnectionFactory" lookup-on-startup="true"></jee:jndi-lookup>
<jee:jndi-lookup id="queue" jndi-name="Queue"
expected-type="javax.jms.Queue" lookup-on-startup="true"/>
ERROR [task-scheduler-4] LoggingHandler:145 -org.springframework.jms.IllegalStateException: MQJCA1019: The connection is closed.; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: MQJCA1019: The connection is closed.
The application attempted to use a JMS connection after it had closed the connection.
Modify the application so that it closes the JMS connection only after it has finished using the connection.
Thanks in Advance!!
The default message listening container should reference the caching connection factory:
<!-- caching connection factory fascade, also implements exception listener -->
<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="connectionFactory"/>
<property name="sessionCacheSize" value="10"/>
<property name="reconnectOnException" value="true"/>
</bean>
<!-- this is the Message Driven POJO (MDP) -->
<bean id="messageDrivenPOJO" class="com.redhat.gss.spring.MessageDrivenPOJO" />
<!-- The message listener container -->
<bean id="messageListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="sessionTransacted" value="true"/>
<property name="concurrentConsumers" value="1"/>
<property name="cacheLevelName" value="CACHE_CONSUMER"/>
<property name="receiveTimeout" value="10000"/>
<property name="sessionAcknowledgeMode" value="2"/>
<property name="messageListener" ref="messageDrivenPOJO"/>
<property name="connectionFactory" ref="cachingConnectionFactory"/>
<property name="exceptionListener" ref="cachingConnectionFactory"/>
<property name="destination" ref="jbossQueue"/>
</bean>
I have developed a JSF application with JPA using Netbeans and GlassFish. It is working fine within the Netbeans environment. Now I want to deploy it a remote GlassFish server with different database settings. Is there any method I can give the database settings when it is deployed in the server for the first time and save the settings afterwords?
I have a persistence.xml file, but the database settings are there in glassfish-resources.xml file.
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="HOPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>dsHiLap2</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/ho" object-type="user" pool-name="connectionPoolHo">
<description/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="connectionPoolHo" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="URL" value="jdbc:derby://localhost:1527/healthofice"/>
<property name="serverName" value="localhost"/>
<property name="PortNumber" value="1527"/>
<property name="DatabaseName" value="healthofice"/>
<property name="User" value="healthoffice"/>
<property name="Password" value="health"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="dsDec2012" object-type="user" pool-name="connectionPoolHo"/>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_ho_hoPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="ho"/>
<property name="User" value="ho"/>
<property name="Password" value="ho"/>
<property name="URL" value="jdbc:derby://localhost:1527/ho"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="dsHo" object-type="user" pool-name="derby_net_ho_hoPool"/>
<jdbc-resource enabled="true" jndi-name="ds2013Feb" object-type="user" pool-name="connectionPoolHo"/>
<jdbc-resource enabled="true" jndi-name="drHoBuddhikaDesktop1" object-type="user" pool-name="derby_net_ho_hoPool"/>
<jdbc-resource enabled="true" jndi-name="drHoBuddhikaLaptop1" object-type="user" pool-name="connectionPoolHo"/>
<jdbc-resource enabled="true" jndi-name="dsHiLap" object-type="user" pool-name="derby_net_ho_hoPool"/>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_ho1_ho1Pool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="ho1"/>
<property name="User" value="ho1"/>
<property name="Password" value="ho1"/>
<property name="URL" value="jdbc:derby://localhost:1527/ho1"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="dsHiLap2" object-type="user" pool-name="derby_net_ho1_ho1Pool"/>
</resources>
You need to use GlassFish deployment plan to configure different connection pool settings for your remote GlassFish server, since glassfish-resources.xml defined application-scoped resources. The application-scoped connection pool is only created during the application deployment. Please see To Deploy an Application or Module by Using a Deployment Plan. Basically your supply a remote server version of glassfish-resources.xml (following module-name.gf-dd-name naming convention) in the deploymentplan.jar.
Another option is not to use the application-scoped resource. You can define the connection pool/data source through the GlassFish Admin console.
I created a custom sitedefinition. In my sitedefition i want to activate a custom feature (i add the guid into my onet.xml).
My custom feature for adding the webpart to the page is creating an error. The error is default.aspx is not found. I thought a page in a sitedefition is created first. After that feature will be activate. Why i receive an error?
SPLimitedWebPartManager collWebParts = web.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
collWebParts.AddWebPart(CustomWebPart, "MainLeft", 1);
collWebParts.SaveChanges(CustomWebPart);
collWebParts.Web.Dispose();
You'd better add you webparts in modules in onet.xml. Just add the tag and use the tag to provision your particular webparts.
A simple sample:
<Modules>
<Module Name="DefaultBlank" Url="" Path="">
<File Url="default.aspx" Path="default.aspx">
<AllUsersWebPart WebPartOrder="0" WebPartZoneID="Right" ID="g_bdef0b56_c2f4_4c5a_bc39_2908a0f61410">
<![CDATA[<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="***.LatestDiscussionsWebPart.LatestDiscussionsWebPart, ***, Version=1.0.0.0, Culture=neutral, PublicKeyToken=20cca094e7d0240a" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="AllowZoneChange" type="bool">True</property>
<property name="ExportMode" type="exportmode">All</property>
<property name="HelpUrl" type="string" />
<property name="Hidden" type="bool">False</property>
<property name="TitleUrl" type="string" />
<property name="Description" type="string">Latest Discussions WebPart</property>
<property name="AllowHide" type="bool">True</property>
<property name="AllowMinimize" type="bool">True</property>
<property name="Title" type="string">Latest Discussions </property>
<property name="ChromeType" type="chrometype">Default</property>
<property name="AllowConnect" type="bool">True</property>
<property name="Width" type="unit" />
<property name="Height" type="unit" />
<property name="HelpMode" type="helpmode">Navigate</property>
<property name="CatalogIconImageUrl" type="string" />
<property name="AllowEdit" type="bool">True</property>
<property name="TitleIconImageUrl" type="string" />
<property name="Direction" type="direction">NotSet</property>
<property name="AllowClose" type="bool">True</property>
<property name="ChromeState" type="chromestate">Normal</property>
</properties>
</data>
</webPart>
</webParts>]]>
</AllUsersWebPart>
</File>
</Module>
Good luck.