-
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.
create temp queue by thread, automatic one reconnecting retry when se…
…nd a message
- Loading branch information
1 parent
8bf7166
commit c1edd6b
Showing
23 changed files
with
301 additions
and
304 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
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
40 changes: 0 additions & 40 deletions
40
.../src/main/java/co/com/bancolombia/commons/jms/internal/listener/MQConnectionListener.java
This file was deleted.
Oops, something went wrong.
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
75 changes: 75 additions & 0 deletions
75
...ain/java/co/com/bancolombia/commons/jms/internal/listener/MQContextTemporaryListener.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,75 @@ | ||
package co.com.bancolombia.commons.jms.internal.listener; | ||
|
||
import co.com.bancolombia.commons.jms.api.MQQueuesContainer; | ||
import co.com.bancolombia.commons.jms.internal.models.MQListenerConfig; | ||
import co.com.bancolombia.commons.jms.internal.reconnect.AbstractJMSReconnectable; | ||
import co.com.bancolombia.commons.jms.utils.MQQueueUtils; | ||
import jakarta.jms.ConnectionFactory; | ||
import jakarta.jms.JMSConsumer; | ||
import jakarta.jms.JMSContext; | ||
import jakarta.jms.JMSException; | ||
import jakarta.jms.MessageListener; | ||
import jakarta.jms.TemporaryQueue; | ||
import lombok.experimental.SuperBuilder; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Log4j2 | ||
@SuperBuilder | ||
public class MQContextTemporaryListener extends AbstractJMSReconnectable<MQContextTemporaryListener> { | ||
private final ConnectionFactory connectionFactory; | ||
private final MessageListener listener; | ||
private final MQListenerConfig config; | ||
private final MQQueuesContainer container; | ||
private JMSConsumer consumer; | ||
private JMSContext context; | ||
private TemporaryQueue tempQueue; | ||
|
||
@Override | ||
protected String name() { | ||
String[] parts = Thread.currentThread().getName().split("-"); | ||
String finalName = "mq-listener-tmp-queue-" + parts[parts.length - 1] + "[" + config.getTempQueueAlias() + "]"; | ||
Thread.currentThread().setName(finalName); | ||
return finalName; | ||
} | ||
|
||
@Override | ||
protected void disconnect() { | ||
container.unregisterFromQueueGroup(config.getTempQueueAlias(), tempQueue); | ||
if (consumer != null) { | ||
try { | ||
consumer.close(); | ||
} catch (Exception ignored) { | ||
// ignore because disconnection | ||
} | ||
} | ||
if (context != null) { | ||
try { | ||
context.close(); | ||
} catch (Exception ignored) { | ||
// ignore because disconnection | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected MQContextTemporaryListener connect() { | ||
log.info("Starting listener {}", getProcess()); | ||
context = connectionFactory.createContext(); | ||
context.setExceptionListener(this); | ||
tempQueue = MQQueueUtils.setupTemporaryQueue(context, config); | ||
consumer = context.createConsumer(tempQueue);//NOSONAR | ||
consumer.setMessageListener(listener); | ||
container.registerToQueueGroup(config.getTempQueueAlias(), tempQueue); | ||
log.info("Listener {} started successfully with queue: {}", getProcess(), shortDestinationName()); | ||
return this; | ||
} | ||
|
||
private String shortDestinationName() { | ||
try { | ||
return tempQueue.getQueueName().split("\\?")[0]; | ||
} catch (JMSException e) { | ||
log.warn("Error getting temp queue name", e); | ||
return "Error getting queue name"; | ||
} | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
...main/java/co/com/bancolombia/commons/jms/internal/listener/MQMultiConnectionListener.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.