-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fixed queues to container, add current connected qm to fixed queue * add tests and fix codesmells * fix codesmells
- Loading branch information
1 parent
5a29c4a
commit eed6f54
Showing
26 changed files
with
725 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
commons-jms-api/src/main/java/co/com/bancolombia/commons/jms/api/MQBrokerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package co.com.bancolombia.commons.jms.api; | ||
|
||
import javax.jms.JMSContext; | ||
import javax.jms.Queue; | ||
|
||
public interface MQBrokerUtils { | ||
void setQueueManager(JMSContext context, Queue queue); | ||
} |
9 changes: 9 additions & 0 deletions
9
commons-jms-api/src/main/java/co/com/bancolombia/commons/jms/api/MQQueuesContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package co.com.bancolombia.commons.jms.api; | ||
|
||
import javax.jms.Queue; | ||
|
||
public interface MQQueuesContainer { | ||
void registerQueue(String key, Queue queue); | ||
|
||
Queue get(String alias); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...-jms-mq/src/main/java/co/com/bancolombia/commons/jms/mq/config/utils/AnnotationUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
commons-jms-mq/src/main/java/co/com/bancolombia/commons/jms/mq/utils/MQUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package co.com.bancolombia.commons.jms.mq.utils; | ||
|
||
|
||
import com.ibm.mq.jms.MQQueue; | ||
import com.ibm.msg.client.jms.JmsReadablePropertyContext; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
import javax.jms.JMSContext; | ||
import javax.jms.JMSException; | ||
import javax.jms.Queue; | ||
import java.lang.reflect.AccessibleObject; | ||
import java.lang.reflect.Field; | ||
|
||
import static com.ibm.msg.client.wmq.common.CommonConstants.WMQ_QUEUE_MANAGER; | ||
|
||
@Log4j2 | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MQUtils { | ||
private static final String CONNECTION_PROPERTY = "connection"; | ||
|
||
public static String extractQMName(JMSContext context) { | ||
try { | ||
Field field = context.getClass().getDeclaredField(CONNECTION_PROPERTY); | ||
AccessibleObject.setAccessible(new AccessibleObject[]{field}, true); | ||
JmsReadablePropertyContext readable = (JmsReadablePropertyContext) field.get(context); | ||
AccessibleObject.setAccessible(new AccessibleObject[]{field}, false); | ||
String qmName = readable.getStringProperty(WMQ_QUEUE_MANAGER); | ||
log.info("Listening queue manager name got successfully: {}", qmName); | ||
return qmName; | ||
} catch (NoSuchFieldException | JMSException | IllegalAccessException e) { | ||
log.warn("Error getting queue manager name from JMSContext", e); | ||
return ""; | ||
} | ||
} | ||
|
||
public static void setQMName(Queue queue, String qmName) { | ||
try { | ||
((MQQueue) queue).setBaseQueueManagerName(qmName); | ||
} catch (JMSException e) { | ||
log.warn("Error setting queue manager name to queue", e); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ms-mq/src/test/java/co/com/bancolombia/commons/jms/mq/config/MQAutoconfiguracionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package co.com.bancolombia.commons.jms.mq.config; | ||
|
||
import co.com.bancolombia.commons.jms.api.MQBrokerUtils; | ||
import co.com.bancolombia.commons.jms.api.MQQueueCustomizer; | ||
import co.com.bancolombia.commons.jms.api.MQQueuesContainer; | ||
import co.com.bancolombia.commons.jms.api.MQTemporaryQueuesContainer; | ||
import com.ibm.mq.jms.MQQueue; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import javax.jms.JMSContext; | ||
import javax.jms.JMSException; | ||
|
||
import static com.ibm.msg.client.wmq.common.CommonConstants.WMQ_TARGET_CLIENT; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class MQAutoconfiguracionTest { | ||
private final MQAutoconfiguration configuration = new MQAutoconfiguration(); | ||
@Mock | ||
private MQQueue queue; | ||
@Mock | ||
private JMSContext context; | ||
|
||
@Test | ||
void shouldCreateCustomizer() throws JMSException { | ||
MQQueueCustomizer customizer = configuration.defaultMQQueueCustomizer(); | ||
customizer.customize(queue); | ||
verify(queue, times(1)).setProperty(WMQ_TARGET_CLIENT, "1"); | ||
} | ||
|
||
@Test | ||
void shouldCreateContainers() { | ||
MQQueuesContainer container = configuration.defaultMQQueuesContainer(); | ||
MQTemporaryQueuesContainer containerTemporary = configuration.defaultMQTemporaryQueuesContainer(container); | ||
Assertions.assertNull(containerTemporary.get("non-existent")); | ||
} | ||
|
||
@Test | ||
void shouldCreateBrokerUtils() throws JMSException { | ||
MQBrokerUtils utils = configuration.defaultMqBrokerUtils(); | ||
utils.setQueueManager(context, queue); | ||
verify(queue, times(1)).setBaseQueueManagerName(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.