英文:
Seedstack ibm mq commit parameter
问题
我正在通过yaml文件配置Seedstack IBM MQ,但我无法找到与消息提交相关的任何参数,因为IBM MQ需要提交它。目前消息仍处于挂起状态。
@JmsMessageListener(connection = "connection1", destinationName = "${queue.myqueue}", destinationType = DestinationType.QUEUE)
public class MyMessageListener implements javax.jms.MessageListener {
private static final Logger LOGGER = LogManager.getLogger();
@Override
@Transactional
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
try {
TextMessage textMessage = (TextMessage) message;
final String messageInXML = textMessage.getText();
英文:
I am doing seedstack ibm mq configuration through yaml file
But i am not able to find any paramter related message commit
Because ibm mq needs to commit it.
As it is message is pending
@JmsMessageListener(connection = "connection1", destinationName = "${queue.myqueue}", destinationType = DestinationType.QUEUE)
public class MyMessageListener implements javax.jms.MessageListener {
private static final Logger LOGGER = LogManager.getLogger();
@Override
@Transactional
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
try {
TextMessage textMessage = (TextMessage) message;
final String messageInXML = textMessage.getText();
答案1
得分: 1
以下是您要翻译的内容:
"我不确定yaml配置为您提供了多少帮助,但如果消息仍然处于挂起状态,那么连接是事务性的,需要执行提交或回滚操作。
您没有分享任何yaml或Java代码,但无论您拥有什么代码,它似乎默认情况下既不执行提交也不执行回滚,这很奇怪。我期望在抛出未捕获的异常时应该执行回滚操作,连接关闭时应该执行默认的提交操作。
查看Seedstack文档,似乎一种常见的模式是注入一个会话(session),而连接和会话都不会被关闭。这反过来表明您可能需要在您的代码中执行提交操作。
如果您的代码类似于以下内容:
@Inject
private Session session;
@Override
@Transactional
@JmsConnection("connection1")
public void sendMessage() {
Destination queue = session.createQueue("queue1");
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage();
message.setText(stringMessage);
producer.send(message);
}
我的初步想法是注解 @Transactional
应该在方法退出时默认执行提交操作,但如果没有执行,则提交操作需要在会话上执行:
@Inject
private Session session;
@Override
@Transactional
@JmsConnection("connection1")
public void sendMessage() {
Destination queue = session.createQueue("queue1");
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage();
message.setText(stringMessage);
producer.send(message);
session.commit();
}
"
英文:
I am not sure how much the yaml configuration is doing for you, but if the messages are pending then the connection is transactional and a commit or rollback needs to happen.
You don't share any yaml or java code, but what ever you have isn't performing neither a commit nor a rollback by default, which is odd. I would expect a rollback should an uncaught exception be thrown, with a default action of commit on connection close.
Looking at Seedstack documentation it seems that a normal pattern is for a session to be injected, and neither connection nor session ever closed. Which in turn indicates that you may need to perform a commit in your code.
If you have code that looks like:
@Inject
private Session session;
@Override
@Transactional
@JmsConnection("connection1")
public void sendMessage() {
Destination queue = session.createQueue("queue1");
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage();
message.setText(stringMessage);
producer.send(message);
}
My initial thoughts are that the annotation @Transactional
should run a commit by default on exit of the method, but if it isn't then the commit needs to be on the session:
@Inject
private Session session;
@Override
@Transactional
@JmsConnection("connection1")
public void sendMessage() {
Destination queue = session.createQueue("queue1");
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage();
message.setText(stringMessage);
producer.send(message);
session.commit();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论