- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
JMS 1.1 规范第 4.4.11 节说:“承认消费消息自动确认收到所有消息 session 已交付这些内容。”
但是,这不是我在 Solace 中观察到的行为。我编写了以下 100 行程序,该程序发送 20 条消息,然后读取消息并交替确认和丢弃它们。结果是所有偶数消息都保留在队列中。
Solace 是否违反了 JMS 规范,还是我遗漏了什么?
package com.example;
import java.util.function.Predicate;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import com.solacesystems.jms.SolConnectionFactory;
import com.solacesystems.jms.SolJmsUtility;
import com.solacesystems.jms.SupportedProperty;
public class SolaceAckTest {
private static final String host = "localhost";
private static final String username = "MyUser";
private static final String password = "MyPassword";
private static final String COUNTER_PROPERTY_NAME = "MyCounter";
private static final String QUEUE_NAME = "MATCHED_1";
private static final int NUM_MESSAGES_TO_SEND = 20;
private static final long SENDING_INTERVAL_IN_MILLISECONDS = 100;
/**
* Determines on which messages we should call
* {@link Message#acknowledge()}.
*/
private static final Predicate<Message> SELECTOR_OF_MESSAGES_TO_ACKNOWLEDGE = new Predicate<Message>() {
@Override
public boolean test(Message m) {
try {
return (m.getIntProperty(COUNTER_PROPERTY_NAME) % 2) == 1;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
};
public static void main(String[] args) throws Exception {
SolConnectionFactory connectionFactory = SolJmsUtility.createConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
connectionFactory.setRespectTTL(true);
QueueConnection queueConnection = connectionFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, SupportedProperty.SOL_CLIENT_ACKNOWLEDGE);
Destination requestDest = queueSession.createQueue(QUEUE_NAME);
queueSession.createConsumer(requestDest).setMessageListener(new MessageListenerThatAcknowledgesSomeMessages());
MessageProducer messageProducer = queueSession.createProducer(requestDest);
queueConnection.start();
for (int counter = 1; counter <= NUM_MESSAGES_TO_SEND; counter++) {
TextMessage msg = queueSession.createTextMessage();
msg.setText("Message #" + counter);
msg.setIntProperty(COUNTER_PROPERTY_NAME, counter);
messageProducer.send(msg);
Thread.sleep(SENDING_INTERVAL_IN_MILLISECONDS);
}
// Prevent the program from terminating.
Thread.sleep(1000);
}
/**
* A listener that calls {@link Message#acknowledge()} only on messages that
* meet the criteria specified by
* {@link SolaceAckTest#SELECTOR_OF_MESSAGES_TO_ACKNOWLEDGE}.
*/
private static class MessageListenerThatAcknowledgesSomeMessages implements MessageListener {
public MessageListenerThatAcknowledgesSomeMessages() {
}
@Override
public void onMessage(Message msg) {
try {
final String text = ((TextMessage) msg).getText();
if (SELECTOR_OF_MESSAGES_TO_ACKNOWLEDGE.test(msg)) {
msg.acknowledge();
System.out.println("Acknowledging message: " + text);
} else {
System.out.println("Not acknowledging message: " + text);
}
} catch (JMSException e) {
e.printStackTrace();
}
}
}
}
最佳答案
我相信蒂姆是正确的。在您的示例中,您似乎使用的是 Solace 扩展,而不是标准 JMS 客户端确认模式。请尝试在创建 session 时指定标准 JMS 客户端确认模式。例如:
QueueSession queueSession = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
您最初指定的 SOL_CLIENT_ACKNOWLEDGE 扩展允许您确认特定消息,而无需隐式确认 session 收到的所有其他消息。如果您有多个工作线程处理来自 session 的消息,这非常有用。每个线程在完成处理后都可以确认其消息,而无需隐式确认其他线程正在处理的消息。
关于java - Solace 不确认之前的消息是否违反了 JMS 规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50507601/
出现以下错误: INSERT INTO GroupMembers VALUES ('Goldfrat', 'Simon Palm') * ERROR at line 1: ORA-02291: int
据称以下代码违反了 OO 指导原则。 public class Main { public static String NAME = "James"; public Main() {
我创建了一个名为 EvenementBean 的 EJB 2 进行测试。然后我就把它删除了。现在每当尝试部署我的 .ear 项目时,我都会收到以下错误: WARN [verifier] EJB
我正在开发的一个应用程序正在使用 Oracle 和 Hibernate 作为 ORM。当我尝试插入 PartyUserObject 时,我不断收到以下错误: could not insert: [Pe
我已经实现了一些代码行: if(condition){ Class a = new Class(); method(a.b(), a.c()); }else{ method(null, n
这个问题在这里已经有了答案: Static analysis of noexcept "violations" in C++ (2 个答案) 关闭 4 年前。 我大量使用 noexcept,不幸的是
我有一个 MVVM 应用程序,在我的几个 VM 中,我使用 CollectionViewSource.GetDefaultView(datasource) 来初始化我的 ICollectionView
当我尝试运行我的网站时,它显示 500 internal server error : Internal Server Error The server encountered an internal
运行生存分析,假设变量的 p 值具有统计显着性 - 假设与结果呈正相关。但是,根据 Schoenfeld 残差,违反了比例风险 (PH) 假设。 在纠正 PH 违规后,以下哪种情况可能发生? p 值可
我知道以下是一个主观问题,但您的指导方针确实有助于我追求干净、可测试的代码。 请考虑以下示例,我认为它违反了一系列设计原则。 public class OfferEligibilityCheckerS
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭10 年前。 Improv
当我尝试将 Paho MQTT javacrript 与 Mosquito MQTT websockets 一起使用时,只要我用来服务页面的 Web 服务器和 Mosquito 位于同一服务器(同一来
我在通过 hibernate 映射 oracle 时遇到问题 我有这些类(class) Stock.java package com.mc.stock; import java.uti
在我的项目中,我试图解决 Sonar 违规问题,我坚持使用这个,我有以下代码 不允许使用以下属性:语言 谁能告诉我如何解决这个 Sonar 违规问题?我可以简单地删除这种“语言”吗属性还是我应该输
我正在尝试记录唯一标识符,所以我无法承受重复记录我的 ID 当我尝试更新名为 Clients 的 SQL Server 表时,我收到类似这样的错误。 Violation of PRIMARY KEY
我正在尝试实现一个解决方案,以在给定的整数列表中找到第 k 个最大的元素,其中重复项具有 O(N*log(N)) Big-O 表示法的平均时间复杂度,其中 N 是列表中元素的数量。 根据我的理解,合并
如果 tuple_size 模板是一个完整的类型,结构化绑定(bind)特性表示它会像分解一样与元组一起使用。当 std::tuple_size 在程序的某一点是给定类型的完整类型而在另一点不完整时会
我们的应用目前已从 google play 中删除,因为它具有 SMS 权限。我们已经删除了权限并上传了一个新的 apk,但项目的状态仍然是删除。我们是否必须等待他们审核,或者是否需要任何其他必要的步
*i 和 u.i 如何在此代码中打印不同的数字,即使 i 被定义为 int *i = &u.i;?我只能假设我在这里触发了 UB,但我看不出具体情况。 ( 如果我选择“C”作为语言,ideone de
您好,我正在 Oracle SQL dev 中开发一个数据库,它试图从另一个表访问外键。我目前正在处理使用以下 CREATE 语句创建的 ItemOrdered 表 CREATE TABLE Item
我是一名优秀的程序员,十分优秀!