Search in sources :

Example 51 with JMSException

use of javax.jms.JMSException in project logging-log4j2 by apache.

the class JmsAppender method append.

@Override
public void append(final LogEvent event) {
    try {
        final Message message = this.manager.createMessage(getLayout().toSerializable(event));
        message.setJMSTimestamp(event.getTimeMillis());
        this.producer.send(message);
    } catch (final JMSException e) {
        throw new AppenderLoggingException(e);
    }
}
Also used : Message(javax.jms.Message) AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException) JMSException(javax.jms.JMSException)

Example 52 with JMSException

use of javax.jms.JMSException in project spring-boot by spring-projects.

the class ArtemisAutoConfigurationTests method embeddedWithPersistentMode.

@Test
public void embeddedWithPersistentMode() throws IOException, JMSException {
    File dataFolder = this.folder.newFolder();
    // Start the server and post a message to some queue
    load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
    final String msgId = UUID.randomUUID().toString();
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    jmsTemplate.send("TestQueue", new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(msgId);
        }
    });
    // Shutdown the broker
    this.context.close();
    // Start the server again and check if our message is still here
    load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
    JmsTemplate jmsTemplate2 = this.context.getBean(JmsTemplate.class);
    jmsTemplate2.setReceiveTimeout(1000L);
    Message message = jmsTemplate2.receive("TestQueue");
    assertThat(message).isNotNull();
    assertThat(((TextMessage) message).getText()).isEqualTo(msgId);
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsTemplate(org.springframework.jms.core.JmsTemplate) JMSException(javax.jms.JMSException) File(java.io.File) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 53 with JMSException

use of javax.jms.JMSException in project spring-boot by spring-projects.

the class JmsHealthIndicatorTests method jmsBrokerCouldNotRetrieveProviderMetadata.

@Test
public void jmsBrokerCouldNotRetrieveProviderMetadata() throws JMSException {
    ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
    given(connectionMetaData.getJMSProviderName()).willThrow(new JMSException("test", "123"));
    Connection connection = mock(Connection.class);
    given(connection.getMetaData()).willReturn(connectionMetaData);
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    given(connectionFactory.createConnection()).willReturn(connection);
    JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
    Health health = indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("provider")).isNull();
    verify(connection, times(1)).close();
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) ConnectionMetaData(javax.jms.ConnectionMetaData) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 54 with JMSException

use of javax.jms.JMSException in project spring-boot by spring-projects.

the class JmsHealthIndicatorTests method jmsBrokerIsDown.

@Test
public void jmsBrokerIsDown() throws JMSException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    given(connectionFactory.createConnection()).willThrow(new JMSException("test", "123"));
    JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
    Health health = indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("provider")).isNull();
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 55 with JMSException

use of javax.jms.JMSException in project spring-framework by spring-projects.

the class JmsInvokerClientInterceptor method invoke.

@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
        return "JMS invoker proxy for queue [" + this.queue + "]";
    }
    RemoteInvocation invocation = createRemoteInvocation(methodInvocation);
    RemoteInvocationResult result;
    try {
        result = executeRequest(invocation);
    } catch (JMSException ex) {
        throw convertJmsInvokerAccessException(ex);
    }
    try {
        return recreateRemoteInvocationResult(result);
    } catch (Throwable ex) {
        if (result.hasInvocationTargetException()) {
            throw ex;
        } else {
            throw new RemoteInvocationFailureException("Invocation of method [" + methodInvocation.getMethod() + "] failed in JMS invoker remote service at queue [" + this.queue + "]", ex);
        }
    }
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) JMSException(javax.jms.JMSException) RemoteInvocationFailureException(org.springframework.remoting.RemoteInvocationFailureException)

Aggregations

JMSException (javax.jms.JMSException)1094 Message (javax.jms.Message)355 Test (org.junit.Test)335 Session (javax.jms.Session)309 TextMessage (javax.jms.TextMessage)302 Connection (javax.jms.Connection)271 MessageProducer (javax.jms.MessageProducer)169 MessageConsumer (javax.jms.MessageConsumer)156 Destination (javax.jms.Destination)105 ObjectMessage (javax.jms.ObjectMessage)100 Queue (javax.jms.Queue)100 MapMessage (javax.jms.MapMessage)70 ConnectionFactory (javax.jms.ConnectionFactory)68 CountDownLatch (java.util.concurrent.CountDownLatch)64 IOException (java.io.IOException)62 BytesMessage (javax.jms.BytesMessage)59 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)54 MessageListener (javax.jms.MessageListener)49 NamingException (javax.naming.NamingException)44 MessageFormatException (javax.jms.MessageFormatException)43