working on it ...

Filters

Explore Public Snippets

Sort by

Found 64 snippets matching: activemq

    public by cghersi  468645  7  8  2

    Load a SOAP endpoint with Apache CXF using JMS transport provided by Apache ActiveMQ

    This is an example on how to load a SOAP web service in order to be able to invoke its methods via JMS transport
    private JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    public MyInterface loadEndPoint() {
    	//try to load from local, if available:
    	boolean loadOK = false;
    	MyInterface result = null;
    	try {
    		Class<?> c = Class.forName("MyImplClass");
    		Method fact = c.getMethod("get");
    		result = (MyInterface) fact.invoke(null);
    		loadOK = true;
    	} catch (ClassNotFoundException e) {
    		log.info("Cannot find MyImplClass, redirecting to  remote access...", e);		
    	} catch (Exception e) {
    		log.warn("Error searching MyImplClass, , redirecting to remote access. Exception is " + e, e);
    	}
    		
    	//load remote endpoint:
    	if (!loadOK) {
    		//detect transport protocol for web services:
    		String brokerAddr = "127.0.0.1"; //the right broker address
    		String queueName = "MyQueueName";
    		String address = "jms:jndi:dynamicQueues/" + queueName + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiConnectionFactoryName=ConnectionFactory&jndiURL=" + brokerAddr;
    
    		log.info("Connecting to " + address);
    		String connString = "tcp://" + brokerAddr + ":61616";
    		ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory("Myusername", "Mypassword", connString);
    
    		SoapBindingConfiguration conf = new SoapBindingConfiguration();
    		//MTOM not supported! .net does not interoperate with cxf mtom impl.
    //		conf.setMtomEnabled(true);
    		conf.setVersion(Soap12.getInstance());
    		factory.setBindingConfig(conf);
    
    		factory.setServiceClass(MyInterface.class);
    		factory.setAddress(address);
    		factory.getFeatures().add(new WSAddressingFeature());
    		factory.getFeatures().add(getJMSConfigFeature(queueName, connFactory, 10000)));
    		Object resObj = factory.create();
    		if ((resObj != null) && (resObj instanceof MyInterface))
    			result = (MyInterface) resObj;
    		}
    
    		return result;
    	}
    }
    
    public static JMSConfigFeature getJMSConfigFeature(String queueName, ActiveMQConnectionFactory connectionFactory, Long receiveTimeout) {
    	JMSConfigFeature jmsConfigFeature = new JMSConfigFeature();
    	JMSConfiguration jmsConfig = new JMSConfiguration();
    	jmsConfig.setUseJms11(true);
    	jmsConfig.setTargetDestination(queueName);
    	jmsConfig.setConnectionFactory(connectionFactory);
    	if (receiveTimeout != null)
    		jmsConfig.setReceiveTimeout(receiveTimeout);
    	jmsConfigFeature.setJmsConfig(jmsConfig);
    	return jmsConfigFeature;
    }

    external by Github  125  0  2  0

    Embedded ActiveMQ dependency

    Embedded ActiveMQ dependency: gistfile1.txt
    total 3.2M
    drwxrwxr-x 2 kohsuke kohsuke 4.0K Oct 10 11:31 .
    drwxrwxr-x 7 kohsuke kohsuke 4.0K Oct 10 11:31 ..
    -rw-rw-r-- 1 kohsuke kohsuke 1.1M Oct 10 11:31 activemq-broker-5.13.2.jar
    -rw-rw-r-- 1 kohsuke kohsuke 1.3M Oct 10 11:31 activemq-client-5.13.2.jar
    -rw-rw-r-- 1 kohsuke kohsuke 670K Oct 10 11:31 activemq-openwire-legacy-5.13.2.jar
    -rw-rw-r-- 1 kohsuke kohsuke  20K Oct 10 11:31 geronimo-j2ee-management_1.1_spec-1.0.1.jar
    -rw-rw-r-- 1 kohsuke kohsuke  32K Oct 10 11:31 geronimo-jms_1.1_spec-1.1.1.jar
    -rw-rw-r-- 1 kohsuke kohsuke  49K Oct 10 11:31 hawtbuf-1.11.jar
    -rw-rw-r-- 1 kohsuke kohsuke  33K Oct 10 11:31 slf4j-api-1.7.13.jar
    
    
    

    external by tallpsmith  114  1  2  0

    Grabbing the Heap Memory from ActiveMQ using Jolokia REST

    Grabbing the Heap Memory from ActiveMQ using Jolokia REST: Grabbing the Heap Memory from ActiveMQ using Jolokia REST
    #curl --silent -XGET --user admin:admin http://localhost:8161/api/jolokia/read/java.lang:type=Memory/HeapMemoryUsage  | python -m json.tool
    {
        "request": {
            "attribute": "HeapMemoryUsage",
            "mbean": "java.lang:type=Memory",
            "type": "read"
        },
        "status": 200,
        "timestamp": 1420596076,
        "value": {
            "committed": 226492416,
            "init": 131005376,
            "max": 954728448,
            "used": 31846216
        }
    }
    
    

    external by Jose Miguel Bataller  45  0  1  0

    Purge messages in ActiveMQ using the command line

    Purge messages in ActiveMQ using the command line: gistfile1.txt
    Purge messages using the activemq-admin command line:
    
    activemq-admin purge --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi --jmxuser camel --jmxpassword password purge com.test.queue.dlq
    
    JMX needs to be enabled to purge messages, check ./conf/activemq.xml has the createConnector enabled:
    
            <managementContext>
                <managementContext createConnector="true"/>
            </managementContext>
    
    

    external by ishara  2876  13  4  0

    ActiveMQ Retry Consumer Example

    ActiveMQ Retry Consumer Example: RetryConsumer
    import org.apache.activemq.ActiveMQConnectionFactory;
    import org.apache.activemq.transport.TransportListener;
    
    import javax.jms.Connection;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageConsumer;
    import javax.jms.MessageListener;
    import javax.jms.Queue;
    import javax.jms.Session;
    import java.io.IOException;
    
    /**
     * Created by ishara on 6/12/14.
     */
    public class RetryConsumer implements TransportListener
    {
        private boolean connected = false;
        private Connection connection = null;
        private MessageConsumer consumer = null;
        private Session session = null;
        private int RETRY_DELAY = 1000;
    
        public void run() throws Exception
        {
    
            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory( "failover:(tcp://localhost:61616)?timeout=1000" );
            factory.setTransportListener( this );
            connection = factory.createConnection();
            while( session == null )
            {
                try
                {
                    session = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );
                }
                catch( JMSException e )
                {
                    e.printStackTrace();
                }
                if( session == null )
                {
                    System.out.println( "Unable to create ActiveMQ Session" );
                    Thread.sleep( RETRY_DELAY );
                }
            }
            connection.start();
            Queue queue = session.createQueue( "TEST" );
            consumer = session.createConsumer( queue );
            MessageListener listener = new MessageListener()
            {
                public void onMessage( Message message )
                {
                    System.out.println( "Message Got" );
                }
            };
            consumer.setMessageListener( listener );
            // send messages
            while( true )
            {
                if( !connected )
                {
                    System.out.println( "Transport Interrupted or IOException" );
                }
                Thread.sleep( RETRY_DELAY );
            }
        }
    
        public void close() throws JMSException
        {
            if( connection != null )
            {
                connection.close();
            }
            if( consumer != null )
            {
                consumer.close();
            }
            if( session != null )
            {
                session.close();
            }
        }
    
        public static void main( String[] args ) throws Exception
        {
            RetryConsumer producer = new RetryConsumer();
            producer.run();
        }
    
        public void transportResumed()
        {
            connected = true;
        }
    
        public void transportInterupted()
        {
            connected = false;
        }
    
        public void onException( IOException error )
        {
            connected = false;
        }
    
        public void onCommand( Object command )
        {
            System.out.println( "Command - " + command );
        }
    }
    
    

    external by rodrigomaia  2804  7  4  0

    ActiveMQ Detected missing/corrupt journal files

    ActiveMQ Detected missing/corrupt journal files: activemq.corrupt_jornal
    http://nishal-tech.blogspot.com.br/2012/09/activemq-detected-missingcorrupt.html
    
    Sometime kahaDB which is used by activeMQ to persist the message, get either corrupted some message/journal gets corrupted or missing. I got few flag which can can configured in activemq.xml.
    
       <persistenceAdapter> 
                <kahaDB directory="${activemq.base}/data/kahadb" 
                        ignoreMissingJournalfiles="true" 
                        checkForCorruptJournalFiles="true" 
                        checksumJournalFiles="true" />
         </persistenceAdapter>  
    
    

    external by Hans-Jacob Melby  34  0  1  0

    Simple JMS client that uses delayed messaging in activeMQ

    Simple JMS client that uses delayed messaging in activeMQ: SimpleDelayExample
    import javax.jms.Connection;
    import javax.jms.Destination;
    import javax.jms.JMSException;
    import javax.jms.MessageProducer;
    import javax.jms.Session;
    import javax.jms.TextMessage;
    
    import org.apache.activemq.ActiveMQConnection;
    import org.apache.activemq.ActiveMQConnectionFactory;
    import org.apache.activemq.ScheduledMessage;
    
    
    
    public class SimpleDelayExample {
    
    	public static void main(String[] args) throws JMSException {
    		// Create a ConnectionFactory
    		String url = ActiveMQConnection.DEFAULT_BROKER_URL;
    		//ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
    		ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
            // Create a Connection
            Connection connection = connectionFactory.createConnection();
            connection.start();
            // Create a Session
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    
            // Create the destination (Topic or Queue)
            Destination destination = session.createQueue("TEST.FOO");
            
            
            MessageProducer producer = session.createProducer(destination);
            TextMessage message = session.createTextMessage("test msg");
            long time = 5 * 1000;
            message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time);
            System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
            producer.send(message);
    
                    // Tell the producer to send the message
            
                    // Clean up
            session.close();
            connection.close();
    		
    	}
    
    }
    
    
    

    external by mroger  34  0  1  0

    ActiveMQ listener

    ActiveMQ listener: SimpleActiveMQListener.java
    @Component
    public class SimpleListener {
    	
      private static final Logger LOGGER = LoggerFactory.getLogger(SimpleListener.class);
          
      @JmsListener(destination = "queue.logback-queue")
      public void receiveOrder(Message message) throws JMSException {
        LoggingEventVO loggingEventVO = (LoggingEventVO) ((ActiveMQObjectMessage)message).getObject();
        
        LOGGER.info("Message '{}' received.", loggingEventVO.getMessage());
      }
    }
    
    

    external by Rafael T. C. Soares (A.K.A Tuelho)  22  0  1  0

    Testing Messaging in JBoss Fuse and ActiveMQ with Camel Routes

    Testing Messaging in JBoss Fuse and ActiveMQ with Camel Routes: fuse-amq-camel-basic-config.md
    * configure an embedded local Messaging Broker
    
    ```
      <!-- This creates an embedded ActiveMQ Broker -->
      <broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" persistent="false">
        <transportConnectors>
          <transportConnector uri="tcp://localhost:61616" />
        </transportConnectors>
      </broker>
    
      <!-- Lets connect the Camel ActiveMQ component to the embedded broker.
           See http://camel.apache.org/activemq.html for more information.
      -->
      <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="failover:tcp://localhost:61616"/>
      </bean>
    ``` 
    
    * configure an inMemory (JVM) Messaging Broker
    
    ```
      <!-- Configure an inVM ActiveMQ Broker for test purposes -->
      <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
         <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
      </bean>
    ```
    
    * a sample Camel route using the `activemq` component endpoint
    ```
      <camelContext xmlns="http://camel.apache.org/schema/spring">
      <route>
        <from uri="file:src/data?noop=true"/>
        <to uri="activemq:personnel.records"/>
      </route>
      <route>
        <from uri="activemq:personnel.records"/>
        <choice>
          <when>
            <xpath>/person/city = 'London'</xpath>
            <to uri="file:target/messages/uk"/>
          </when>
          <otherwise>
            <to uri="file:target/messages/others"/>
          </otherwise>
        </choice>
      </route>
    </camelContext>
    ```
    
    

    external by Jakub Korab  22  0  1  0

    ActiveMQ Perf Test Pom

    ActiveMQ Perf Test Pom: pom.xml
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com.fusesource.test</groupId>
      <artifactId>activemq-perftest</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>jar</packaging>
      <name>ActiveMQ :: Performance Test</name>
      <description>Performance Testing Framework for ActiveMQ</description>
    
      <properties>
        <activemq.version>5.12.0</activemq.version>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.activemq.tooling</groupId>
            <artifactId>activemq-perf-maven-plugin</artifactId>
            <version>${activemq.version}</version>
          </plugin>
          <plugin>
            <groupId>org.apache.activemq.tooling</groupId>
             <artifactId>activemq-memtest-maven-plugin</artifactId>
             <version>${activemq.version}</version>
          </plugin>
        </plugins>
      </build>
    </project>
    
    
    
    • Public Snippets
    • Channels Snippets