forked from SolaceProducts/solace-spring-cloud
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,094 additions
and
432 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
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
98 changes: 98 additions & 0 deletions
98
...pring/cloud/stream/binder/inbound/acknowledge/TransactedJCSMPAcknowledgementCallback.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,98 @@ | ||
package com.solace.spring.cloud.stream.binder.inbound.acknowledge; | ||
|
||
import com.solace.spring.cloud.stream.binder.util.ErrorQueueInfrastructure; | ||
import com.solace.spring.cloud.stream.binder.util.SolaceAcknowledgmentException; | ||
import com.solacesystems.jcsmp.JCSMPException; | ||
import com.solacesystems.jcsmp.transaction.RollbackException; | ||
import com.solacesystems.jcsmp.transaction.TransactedSession; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.integration.acks.AcknowledgmentCallback; | ||
|
||
class TransactedJCSMPAcknowledgementCallback implements AcknowledgmentCallback { | ||
private final ThreadLocal<TransactedSession> transactedSessionThreadLocal = new ThreadLocal<>(); | ||
private final ErrorQueueInfrastructure errorQueueInfrastructure; | ||
private boolean acknowledged = false; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(TransactedJCSMPAcknowledgementCallback.class); | ||
|
||
TransactedJCSMPAcknowledgementCallback(TransactedSession transactedSession, | ||
ErrorQueueInfrastructure errorQueueInfrastructure) { | ||
this.transactedSessionThreadLocal.set(transactedSession); | ||
this.errorQueueInfrastructure = errorQueueInfrastructure; | ||
} | ||
|
||
@Override | ||
public void acknowledge(Status status) { | ||
if (acknowledged) { | ||
LOGGER.debug("transaction is already resolved"); | ||
return; | ||
} | ||
|
||
TransactedSession transactedSession = transactedSessionThreadLocal.get(); | ||
if (transactedSession == null) { | ||
throw new UnsupportedOperationException("Transactions must be resolved on the message handler's thread"); | ||
} | ||
|
||
try { | ||
switch (status) { | ||
case ACCEPT -> { | ||
try { | ||
transactedSession.commit(); | ||
} catch (JCSMPException e) { | ||
if (!(e instanceof RollbackException)) { | ||
try { | ||
LOGGER.debug("Rolling back transaction"); | ||
transactedSession.rollback(); | ||
} catch (JCSMPException e1) { | ||
e.addSuppressed(e1); | ||
} | ||
} | ||
|
||
throw e; | ||
} | ||
} | ||
case REJECT -> { | ||
if (!republishToErrorQueue()) { | ||
transactedSession.rollback(); | ||
} | ||
} | ||
case REQUEUE -> transactedSession.rollback(); | ||
} | ||
} catch (Exception e) { | ||
throw new SolaceAcknowledgmentException("Failed to resolve transaction", e); | ||
} | ||
|
||
acknowledged = true; | ||
} | ||
|
||
/** | ||
* Send the message to the error queue and acknowledge the message. | ||
* | ||
* @return {@code true} if successful, {@code false} if {@code errorQueueInfrastructure} is not | ||
* defined. | ||
*/ | ||
private boolean republishToErrorQueue() { | ||
return false; //TODO | ||
// if (errorQueueInfrastructure == null) { | ||
// return false; | ||
// } | ||
// | ||
// LOGGER.debug("{} {}: Will be republished onto error queue {}", | ||
// XMLMessage.class.getSimpleName(), messageContainer.getMessage().getMessageId(), | ||
// errorQueueInfrastructure.getErrorQueueName()); | ||
// | ||
// try { | ||
// errorQueueInfrastructure.createCorrelationKey(messageContainer, flowReceiverContainer).handleError(); | ||
// } catch (Exception e) { | ||
// throw new SolaceAcknowledgmentException( | ||
// String.format("Failed to send XMLMessage %s to error queue", | ||
// messageContainer.getMessage().getMessageId()), e); | ||
// } | ||
// return true; | ||
} | ||
|
||
@Override | ||
public boolean isAcknowledged() { | ||
return acknowledged; | ||
} | ||
} |
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.