ActiveMQ - delete/purge all queue via command line - jms

Is there a way to delete / purge all queues in ActiveMQ via the command line (win/linux)?
I could only find the commands for a specific queue.
Or maybe there's a way to do this via the activeMQ admin? Again, I only found how to delete/purge the queues one by one, which can be very tedious.
Thanks!

You can do tweak your activemq.xml a bit:
<broker deleteAllMessagesOnStartup="true" ...>
This works with KahaDB message stores (it has problems with JDBC message stores), all your messages get deleted and subsequently queues are cleared.
As you want all queues to be deleted, restarting the broker won't be a costly option to clean everything up.
The purge will happen on 'every' restart

I developed my own ActiveMQ command line utility (activemq-cli) to do this. You can find it here: https://github.com/antonwierenga/activemq-cli (command 'purge-all-queues' or 'remove-all-queues').

As of version 5.0 it looks like this can be done using the CLI provided with ActiveMQ itself:
$ ActiveMQ/bin/activemq purge

1- go to amq bin folder, in my case:
cd /opt/amq/bin
2- run amq client:
./client
3- run purge on desired queue
activemq:purge <QUEUE NAME HERE>

Another possibility is to deploy a small Camel route in a container (e.g. Apache ServiceMix) or simply by executing a java program which contain the route.
For example here is the route I currently use on my development computer where I also have the ServiceMix installed:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<cm:property-placeholder persistent-id="amq.cleanup" update-strategy="reload">
<cm:default-properties>
<cm:property name="amq.local.url" value="tcp://localhost:61616" />
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<onException useOriginalMessage="true">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="activemq:queue:CLEANUP_DLQ" />
</onException>
<route id="drop-all-queues" autoStartup="true">
<from uri="activemq:queue:*.>" />
<stop/>
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${amq.local.url}" />
</bean>
</blueprint>

Related

How load multiple camel context in spring

I want to upload multiple camel context files ( camel-context.xml ; camel-context2.xml ) in spring java application. I am trying the below way to upload files. But only single file gets loaded.
#SpringBootApplication
#ImportResource({"classpath:camel*.xml"})
In the below snapshot in console blue marked gives success response , red shows error.
Note : I have tried this approach as well . Didnt workout.
#ImportResource("camel-context.xml", "camel-context2.xml")
https://camel.apache.org/manual/latest/camel-3-migration-guide.html#_multiple_camelcontexts_per_application_not_supported
Support for multiple CamelContexts has been removed and only 1 CamelContext per deployment is supported. The latter was not recommended anyway and was also not 100% implemented (for example in camel-cdi). For Camel 3 only 1 CamelContext per deployment is recommended and supported.
But you can do the following way of separating your route configurations as this is still one camel context. https://camel.apache.org/manual/latest/faq/how-do-i-import-routes-from-other-xml-files.html
File 1:
<beans ....">
<routeContext id="myCoolRoutes" xmlns="http://camel.apache.org/schema/spring">
<route id="cool">
<from uri="direct:start"/>
<to uri="mock:result"/>
</route>
<route id="bar">
<from uri="direct:bar"/>
<to uri="mock:bar"/>
</route>
</routeContext>
</beans>
File 2: (File 1 is imported)
<beans ..>
<import resource="myCoolRoutes.xml"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<routeContextRef ref="myCoolRoutes"/>
<route id="inside">
<from uri="direct:inside"/>
<to uri="mock:inside"/>
</route>
</camelContext>
</beans>

Ensure ordered shutdown of bundles in karaf

For a simple use-case, I have two bundles in Karaf as:
Bundle-Shared-Library
Bundle-My-Implementation -> depends on (1) Bundle-Shared-Library, mentioned in blueprint via depends-on attribute of the bean
Steps that I am following:
Load Bundle(1)
Load Bundle(2)
Shutdown karaf
It is evident that (2) is dependent on (1). While shutting down Karaf, Bundle(1) gets removed first, this results in the loss of in-flight messages as it cannot find its dependency and cannot process further.
I tried setting the start level of (1) both higher and lower than that of bundle(2). This did not help.
Also, I tried setting org.apache.aries.blueprint.preemptiveShutdown=false in etc/config.properties. This did not help as well.
Am I missing something here?
-- EDIT 1 --
After looking a bit over here and there, I found out that we can set a custom value for timeout in DefaultShutdownStrategy. So, as a workaround, I have done following:
<bean id="shutdownStrategy" class="org.apache.camel.impl.DefaultShutdownStrategy">
<property name="timeout" value="1" />
</bean>
I understand that this is not a clean and optimal way to do. For the time being, it somehow helps me from losing a lot of in-flight messages.
But, any suggestion or feedback would be great.
-- EDIT 2 -- Adding Blueprint File of Bundle 1
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.3.0"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.3.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.3.0.xsd
">
<!-- persistent-id for shared context -->
<cm:property-placeholder persistent-id="xxx.shared" update-strategy="none" >
<cm:default-properties>
...
</cm:default-properties>
</cm:property-placeholder>
<!--jms broker connection-->
<reference id="jmsProducerConnectionFactory" interface="javax.jms.ConnectionFactory" filter="(osgi.jndi.service.name=jms/xxx.producer)" availability="mandatory" />
<bean id="xxx-producer" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsProducerConnectionFactory"/>
</bean>
<!-- Source DB Reference -->
<reference id="XDataSource" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=xxx-datasource)" availability="mandatory"/>
<!-- Datawarehouse DB Reference -->
<reference id="dw" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=xdb-datasource)" availability="mandatory"/>
<bean id="prs" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="XDataSource"/>
</bean>
<bean id="timestamp" class="org.library.shared.TimestampImplementation" destroy-method="synchronize" depends-on="dw">
<argument index="0" ref="dw" />
<argument index="2" value="Orders" />
</bean>
<bean id="shutdownStrategy" class="org.apache.camel.impl.DefaultShutdownStrategy">
<property name="timeout" value="1" />
</bean>
<camelContext id="camel-context" xmlns="http://camel.apache.org/schema/blueprint" depends-on="timestamp">
<packageScan>
<package>org.xyz.orders.routing</package>
</packageScan>
</camelContext>
</blueprint>
The other bundle is simply a collection of few classes (a shared library), which I have included as a maven dependency. There is no blueprint file for that bundle.
Due to organizational issues, I have used dummy names at some places.

Jackrabbit repository could not be accessed from karaf container

I am trying to access a jackrabbit repository through rmi from karaf container
I developped a camel route which save a file into jackrabbit repository
<bean id="repository"
class="org.apache.jackrabbit.rmi.repository.URLRemoteRepository">
<argument value="http://localhost:8020/rmi" />
</bean>
<camelContext id="blueprintContext" trace="false"
xmlns="http://camel.apache.org/schema/blueprint">
<route id="depotfichiersurjcr">
<from uri="file:/C:/data?recursive=false&noop=true" />
<!-- log message="message1 ${body}"/ -->
<setHeader headerName="CamelJcrNodeName">
<constant>node</constant>
</setHeader>
<setHeader headerName="my.contents.property">
<simple>${bodyAs(String)}</simple>
<!-- constant>content</constant -->
</setHeader>
<setBody>
<constant></constant>
</setBody>
<to uri="jcr://admin:admin#repository/default?deep=true&eventTypes=3&noLocal=false" />
<to uri="direct:a" />
</route>
</camelContext>
the route works fine with mvn camel:run
the same route doesnt work inside the karaf container , i got :
javax.jcr.RepositoryException: Remote repository not found: The resource at http://localhost:8020/rmi could not be retrieved
at org.apache.jackrabbit.rmi.repository.URLRemoteRepositoryFactory.getRemoteRepository(URLRemoteRepositoryFactory.java:84)[1626:org.apache.jackrabbit.jackrabbit-jcr-rmi:2.6.2]
at org.apache.jackrabbit.rmi.repository.AbstractRemoteRepositoryFactory.getRepository(AbstractRemoteRepositoryFactory.java:57)[1626:org.apache.jackrabbit.jackrabbit-jcr-rmi:2.6.2]
at org.apache.jackrabbit.rmi.repository.ProxyRepository.login(ProxyRepository.java:199)[1626:org.apache.jackrabbit.jackrabbit-jcr-rmi:2.6.2]
at org.apache.jackrabbit.rmi.repository.ProxyRepository.login(ProxyRepository.java:233)[1626:org.apache.jackrabbit.jackrabbit-jcr-rmi:2.6.2]
at com.sagemcom.Content.process(Content.java:21)[1618:content:0.0.1.SNAPSHOT]
at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:157)[171:org.apache.camel.camel-core:2.13.2]
at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:68)[171:org.apache.camel.camel-core:2.13.2]
at java.util.TimerThread.mainLoop(Timer.java:555)[:1.7.0_75]
at java.util.TimerThread.run(Timer.java:505)[:1.7.0_75]
Caused by: java.io.IOException: Server returned HTTP response code: 503 for URL: http://localhost:8020/rmi
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1627)[:1.7.0_75]
at java.net.URL.openStream(URL.java:1037)[:1.7.0_75]
at org.apache.jackrabbit.rmi.repository.URLRemoteRepositoryFactory.getRemoteRepository(URLRemoteRepositoryFactory.java:61)[1626:org.apache.jackrabbit.jackrabbit-jcr-rmi:2.6.2]
... 15 more
is there any specific configurations that should be done to let the karaf container see the jackrabbit url, any suggestion will be welcome , Thanks .
In the case of the testcase the configuration is from the baseclass, which may need to be added to camel context.
Here's an example configuration from a camel example for the rmi:
<bean id="rmiServer" class="java.rmi.registry.LocateRegistry" factory-method="createRegistry">
<constructor-arg index="0" value="${port}"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring" depends-on="rmiServer">
<endpoint id="rmiService"
uri="rmi://localhost:${port}/helloServiceBean?remoteInterfaces=org.apache.camel.example.osgi.HelloService"/>
<!-- expose a RMI service as a Camel route -->
<camel:route>
<from ref="rmiService"/>
<to uri="log:Incoming request on RMI"/>
<to uri="bean:helloServiceBean"/>
</camel:route> </camelContext>
Now this is typically needed if you're using rmi.
In the case that you have just described, we need the JndiRegistry.
Can you try adding the following to the camel context
<bean id="registry" class="org.apache.camel.impl.JndiRegistry"/>
In the case of the JCR Jackrabbit try the following bean configuration:
<bean id="repository" class="org.apache.jackrabbit.rmi.repository.URLRemoteRepository">
<argument value="http://localhost:8020/rmi" />
</bean>

How Wso2CEP pick the messages in JMS

I am using wso2cep 3.0.0 and activemq5.8.0 As per CEP documents i wish to Publish events using CEP. For that i started activemq with 2 define QUEUES with the name jmsProxy for incoming message and JmsProxy for out message.I added required jars in CEP lib activemq-broker-5.8.0.jar,activemq-client-5.8.0.jar,axiom.jar,geronimo-j2ee-management_1.1_spec-1.0.1.jar,geronimo-jms_1.1_spec-1.1.1.jar,hawtbuf-1.2.jar,xpp3-1.1.4c.jar,xstream-1.4.4.jar
my configuration is like this InputEventAdaptor
<?xml version="1.0" encoding="UTF-8"?>
<inputEventAdaptor name="jmsProxy" statistics="disable" trace="enable"
type="jms" xmlns="http://wso2.org/carbon/eventadaptormanager">
<property name="java.naming.provider.url">tcp://localhost:61616</property>
<property name="transport.jms.SubscriptionDurable">true</property>
<property name="transport.jms.DurableSubscriberName">jmsProxy</property>
<property name="transport.jms.UserName">admin</property>
<property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
<property name="transport.jms.Password">admin</property>
<property name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</property>
<property name="transport.jms.DestinationType">queue</property>
</inputEventAdaptor>
above for incoming messages which will pick the messages from jmsProxy queue But its unable to pick the message from jmsProxy Queue.How would i initiate this to get the message into CEP and outputEventAdaptor I need to intialize some thing for jms could pick the messages from jMS why because i have tried in many ways all the configuration is ok but unable to pick the message from JMS
<?xml version="1.0" encoding="UTF-8"?>
<outputEventAdaptor name="JmsProxy" statistics="disable" trace="disable"
type="jms" xmlns="http://wso2.org/carbon/eventadaptormanager">
<property name="java.naming.security.principal">admin</property>
<property name="java.naming.provider.url">tcp://localhost:61616</property>
<property name="java.naming.security.credentials">admin</property>
<property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
<property name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</property>
<property name="transport.jms.DestinationType">queue</property>
</outputEventAdaptor>
event builder configuration like this
<?xml version="1.0" encoding="UTF-8"?>
<eventBuilder name="ReadingsDtoBuilder" statistics="disable"
trace="disable" xmlns="http://wso2.org/carbon/eventbuilder">
<from eventAdaptorName="jmsProxy" eventAdaptorType="jmsProxy">
<property name="transport.jms.Destination">JmsProxy</property>
</from>
<mapping customMapping="disable"
parentXpath="//ReadingsLiteTaildtos" type="xml">
<property>
<from xpath="//ReadingsLiteTaildto/ParameterId"/>
<to name="meta_parameterId" type="string"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/Slno"/>
<to name="meta_slno" type="string"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/FinalValue"/>
<to name="finalValue" type="int"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/InputText"/>
<to name="inputText" type="string"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/InputValue"/>
<to name="inputValue" type="double"/>
</property>
</mapping>
<to streamName="org.sample.readings.dto.stream" version="1.0.0"/>
</eventBuilder>
The execution plan can be as follows.like this
<?xml version="1.0" encoding="UTF-8"?>
<executionPlan name="ReadingsAnalyzer" statistics="disable"
trace="disable" xmlns="http://wso2.org/carbon/eventprocessor">
<description>This execution plan analyzes readings and triggers notifications based on threshold.</description>
<siddhiConfiguration>
<property name="siddhi.enable.distributed.processing">false</property>
<property name="siddhi.persistence.snapshot.time.interval.minutes">0</property>
</siddhiConfiguration>
<importedStreams>
<stream as="readings" name="org.sample.readings.dto.stream" version="1.0.0"/>
</importedStreams>
<queryExpressions><![CDATA[from readings[finalValue > 100]
select *
insert into notificationStream;]]></queryExpressions>
<exportedStreams>
<stream name="notificationStream" valueOf="notificationStream" version="1.0.0"/>
</exportedStreams>
</executionPlan
I defined streams inside stream-manager-config.xml similar to the following.
<streamDefinition name="org.sample.readings.dto.stream" version="1.0.0">
<metaData>
<property name="parameterId" type="STRING"/>
<property name="slno" type="STRING"/>
</metaData>
<payloadData>
<property name="finalValue" type="INT"/>
<property name="inputText" type="STRING"/>
<property name="inputValue" type="DOUBLE"/>
</payloadData>
</streamDefinition>
<streamDefinition name="notificationStream" version="1.0.0">
<metaData>
<property name="parameterId" type="STRING"/>
<property name="slno" type="STRING"/>
</metaData>
<payloadData>
<property name="finalValue" type="INT"/>
<property name="inputText" type="STRING"/>
<property name="inputValue" type="DOUBLE"/>
</payloadData>
</streamDefinition>
its look like all well while i am sending any message to my jmsProxy queue the message is not reflecting to CEP for event and i am getting this message in CEP.
Means its unable to get the message into CEP and i am getting errors like this
[2014-02-18 11:57:53,159] INFO - {EventBuilderDeployer} Event Builder undeployed successfully : ReadingsDtoBuilder.xml
[2014-02-18 11:57:53,160] INFO - {EventBuilderDeployer} Event builder deployment held back and in inactive state :ReadingsDtoBuilder, Waiting for Input Event Adaptor dependency :jmsProxy
[2014-02-18 12:03:58,006] INFO - {InputEventAdaptorConfigurationFilesystemInvoker} Input Event Adaptor configuration deleted from file system : jmsProxy.xml
[2014-02-18 12:03:58,006] INFO - {InputEventAdaptorDeployer} Input Event Adaptor undeployed successfully : jmsProxy.xml
[2014-02-18 12:03:58,008] INFO - {InputEventAdaptorConfigurationFilesystemInvoker} Input Event Adaptor configuration saved in th filesystem : jmsProxy
[2014-02-18 12:03:58,009] INFO - {InputEventAdaptorDeployer} Input Event Adaptor deployed successfully and in active state : jmsProxy
[2014-02-18 12:03:58,009] INFO - {EventBuilderDeployer} Event Builder undeployed successfully : ReadingsDtoBuilder.xml
[2014-02-18 12:03:58,009] INFO - {EventBuilderDeployer} Event builder deployment held back and in inactive state :ReadingsDtoBuilder, Waiting for Input Event Adaptor dependency :jmsProxy
I am really fed up with wso2 docs no proper explanation on any topic.How its wirk how INCOMING message will get into input event builder Please help me to get out from this issue.
Thanks in advance,
Faisal shaik
Looking at your configuration, it seems that you have specified the input adaptor type as 'jmsProxy' which is incorrect. It should be corrected as simply 'jms'. i.e.
<from eventAdaptorName="jmsProxy" eventAdaptorType="jms">
The way the JMS connection works is as follows. The connection details are specified by the Input event adaptor. But the subscription to a particular topic or listening on a particular queue happens only after the event builder configuration is specified since the topic/queue name is specified in the event builder configuration as the property 'transport.jms.Destination'.
So if you specified the Destination as 'JmsProxy' in the event builder configuration, make sure that a queue by the name of 'JmsProxy' exists in the ActiveMQ broker and that events are published to this queue.
The easiest way to troubleshoot the issue you are encountering would be to enable tracing of CEP artifacts. Each event goes through the sequence of Input Event Adaptor -> Event Builder -> Event Processor (Execution Plan) -> Event Formatter -> Output Event Adaptor. If you enable tracing of all 5 artifacts and tracing reports incoming and outgoing events at Input Event Adaptor and only incoming events at Event Builder, you can conclude that the issue is in the event builder configuration and so on.
If you still encounter an issue after fixing the Input Event Adaptor type, please enable tracing and share the relevant messages printed in the trace to identify in which artifact the issue is arising.
Hope this helps,

Activating Spring Profile active JVM arguments in GWT hosted mode

I have a spring profile configuration as shown below
<beans profile="dev">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${db.driverClassName}" />
<property name="jdbcUrl" value="dfgdfg" />
<property name="user" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
</beans>
<beans profile="prod">
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/Test"/>
</beans>
I am trying to make one of this active via the VM argument -Dspring.profiles.active="dev" . This works in Tomcat and so does the context-param route in Hosted mode via the gwt-maven-plugin but I can't get the VM arguments to work . I tried mvn -Dspring.profiles.active="dev" gwt:run also tried to pass -Dspring.profiles.active="dev" via the VM arguments under the JRE tab in run configurations along with the goal gwt:run . I also tried the environment tab and even -Dspring.profiles.active=dev but the NoSuchBeanDefinitionException doesn't budge . Is this because of the limited capability of the embedded server ?
No, simply gwt:maven plugin is kind of strange and it doesn't pass system properties to the launched JVM instance, and the only way to pass parameters is to put it into <extraJvmArgs> in plugin configuration e.g. in your case you have to add following to the configuration tag of gwt plugin:
<extraJvmArgs>-Dspring.profiles.active=dev</extraJvmArgs>
God knows why this works only this way, I wish there were some other normal way.

Resources