Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.infra.core.CamelContextExtension;
import org.apache.camel.test.infra.core.DefaultCamelContextExtension;
import org.apache.camel.test.infra.core.TransientCamelContextExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.IllegalStateException;

public class JmsInOnlyDisableTimeToLiveTest extends AbstractJMSTest {

private static final Logger LOG = LoggerFactory.getLogger(JmsInOnlyDisableTimeToLiveTest.class);

@Order(2)
@RegisterExtension
public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension();
public static CamelContextExtension camelContextExtension = new TransientCamelContextExtension();
protected CamelContext context;
protected ProducerTemplate template;
protected ConsumerTemplate consumer;
Expand All @@ -47,9 +46,7 @@ public class JmsInOnlyDisableTimeToLiveTest extends AbstractJMSTest {

@Test
public void testInOnlyExpired() throws Exception {
MyCoolBean cool = new MyCoolBean();
cool.setProducer(template);
cool.setConsumer(consumer);
MyCoolBean cool = new MyCoolBean(consumer, template, "JmsInOnlyDisableTimeToLiveTest");

getMockEndpoint("mock:result").expectedBodiesReceived("World 1");

Expand All @@ -72,9 +69,7 @@ public void testInOnlyExpired() throws Exception {

@Test
public void testInOnlyDisabledTimeToLive() throws Exception {
MyCoolBean cool = new MyCoolBean();
cool.setProducer(template);
cool.setConsumer(consumer);
MyCoolBean cool = new MyCoolBean(consumer, template, "JmsInOnlyDisableTimeToLiveTest");

getMockEndpoint("mock:result").expectedBodiesReceived("World 2");

Expand Down Expand Up @@ -132,44 +127,4 @@ void setUpRequirements() {
consumer = camelContextExtension.getConsumerTemplate();
}

public static class MyCoolBean {
private int count;
private ConsumerTemplate consumer;
private ProducerTemplate producer;

public void setConsumer(ConsumerTemplate consumer) {
this.consumer = consumer;
}

public void setProducer(ProducerTemplate producer) {
this.producer = producer;
}

public void someBusinessLogic() {
// loop to empty queue
while (true) {
// receive the message from the queue, wait at most 2 sec
try {
String msg = consumer.receiveBody("activemq:JmsInOnlyDisableTimeToLiveTest.in", 2000, String.class);
if (msg == null) {
// no more messages in queue
break;
}
// do something with body
msg = "Hello " + msg;

// send it to the next queue
producer.sendBodyAndHeader("activemq:JmsInOnlyDisableTimeToLiveTest.out", msg, "number", count++);
} catch (IllegalStateException e) {
if (e.getCause() instanceof jakarta.jms.IllegalStateException) {
// session is closed
LOG.warn("JMS Session is closed");
break;
}
}

}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public class JmsInOutDisableTimeToLiveTest extends AbstractJMSTest {

@Test
public void testInOutExpired() throws Exception {
MyCoolBean cool = new MyCoolBean();
cool.setProducer(template);
cool.setConsumer(consumer);
MyCoolBean cool = new MyCoolBean(consumer, template, "JmsInOutDisableTimeToLiveTest");

getMockEndpoint("mock:result").expectedMessageCount(0);
getMockEndpoint("mock:end").expectedMessageCount(0);
Expand All @@ -66,9 +64,7 @@ public void testInOutExpired() throws Exception {

@Test
public void testInOutDisableTimeToLive() throws Exception {
MyCoolBean cool = new MyCoolBean();
cool.setProducer(template);
cool.setConsumer(consumer);
MyCoolBean cool = new MyCoolBean(consumer, template, "JmsInOutDisableTimeToLiveTest");

getMockEndpoint("mock:result").expectedMessageCount(0);
getMockEndpoint("mock:end").expectedBodiesReceived("Hello World 2");
Expand Down Expand Up @@ -121,37 +117,4 @@ void setUpRequirements() {
template = camelContextExtension.getProducerTemplate();
consumer = camelContextExtension.getConsumerTemplate();
}

public static class MyCoolBean {
private int count;
private ConsumerTemplate consumer;
private ProducerTemplate producer;

public void setConsumer(ConsumerTemplate consumer) {
this.consumer = consumer;
}

public void setProducer(ProducerTemplate producer) {
this.producer = producer;
}

public void someBusinessLogic() {
// loop to empty queue
while (true) {
// receive the message from the queue, wait at most 2 sec
String msg = consumer.receiveBody("activemq:JmsInOutDisableTimeToLiveTest.in", 2000, String.class);
if (msg == null) {
// no more messages in queue
break;
}

// do something with body
msg = "Hello " + msg;

// send it to the next queue
producer.sendBodyAndHeader("activemq:JmsInOutDisableTimeToLiveTest.out", msg, "number", count++);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.camel.component.jms;

import org.apache.camel.ConsumerTemplate;
import org.apache.camel.ProducerTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.IllegalStateException;

final class MyCoolBean {
private static final Logger LOG = LoggerFactory.getLogger(MyCoolBean.class);

private int count;
private final ConsumerTemplate consumer;
private final ProducerTemplate producer;
private final String queueName;

public MyCoolBean(ConsumerTemplate consumer, ProducerTemplate producer, String queueName) {
this.consumer = consumer;
this.producer = producer;
this.queueName = queueName;
}

public void someBusinessLogic() {
// loop to empty queue
while (true) {
// receive the message from the queue, wait at most 2 sec
try {
String msg = consumer.receiveBody("activemq:" + queueName + ".in", 2000, String.class);
if (msg == null) {
// no more messages in queue
break;
}
// do something with body
msg = "Hello " + msg;

// send it to the next queue
producer.sendBodyAndHeader("activemq:" + queueName + ".out", msg, "number", count++);
} catch (IllegalStateException e) {
if (e.getCause() instanceof jakarta.jms.IllegalStateException) {
// session is closed
LOG.warn("JMS Session is closed");
break;
}
}

}
}
}