- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的发布者代码如下所示:
public abstract class PubSubPublisher {
private static final Logger LOGGER = LoggerFactory.getLogger(PubSubPublisher.class);
private final PubSubTemplate pubSubTemplate;
protected PubSubPublisher(PubSubTemplate pubSubTemplate) {
this.pubSubTemplate = pubSubTemplate;
}
protected abstract String topic(String topicName);
public void publish(String topicName, String message) throws StatusRuntimeException {
LOGGER.info("Publishing to topic [{}]. Message: [{}]", topicName, message);
pubSubTemplate.publish(topicName, message);
}
}
我的组件
@Component
public class HelloPubSubPublisher extends PubSubPublisher {
@Autowired
public HelloPubSubPublisher(PubSubTemplate pubSubTemplate) throws StatusRuntimeException{
super(pubSubTemplate);
}
@Override
protected String topic(String topicName) {
return topicName;
}
}
现在在我的服务层上,我如何获得我是否成功将消息发布到主题的天气,请注意我正在使用的所有 google api 都是异步的。
try {
publisher.publish(topicName, payload);
}catch (Exception e) {
LOGGER.error("ioException occured: "+e);
throw new TopicNotFoundException();
}
不幸的是,我无法捕获任何错误,程序光标没有进入 catch block 。
最终,我想知道代码是否将消息推送到主题中,如果没有,那么我必须记录它并将该错误抛给客户端,而我当前的代码通过适当的异常处理不会发生这种情况。
感谢任何帮助或指导,谢谢。
最佳答案
使用函数 publish()
,您应该能够捕获 future
,您可以在其中检查消息是否已发布。
您在 Google's PubSub documentation 上有一个例子:
// Once published, returns a server-assigned message id (unique within the topic)
ApiFuture<String> future = publisher.publish(pubsubMessage);
// Add an asynchronous callback to handle success / failure
ApiFutures.addCallback(
future,
new ApiFutureCallback<String>() {
@Override
public void onFailure(Throwable throwable) {
if (throwable instanceof ApiException) {
ApiException apiException = ((ApiException) throwable);
// details on the API exception
System.out.println(apiException.getStatusCode().getCode());
System.out.println(apiException.isRetryable());
}
System.out.println("Error publishing message : " + message);
}
@Override
public void onSuccess(String messageId) {
// Once published, returns server-assigned message ids (unique within the topic)
System.out.println(messageId);
}
},
MoreExecutors.directExecutor());
关于spring-boot - 带有 spring : know the message is publish or not? 的 PubSub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59266625/
对新版本 com.google.cloud.pubsub.spi.v1.Publisher.publish(pubsubMessage).get() 的调用永远挂起。我不确定问题是什么。 代码片段:
根据这里:https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage 当发布者向队列发送消息时,不应填充时间戳字段。所以这
Google PubSub 是否适合小批量(10 条消息/秒)但任务关键型消息传递,保证在任何固定时间段内及时传递每条消息? 或者,它是否更适合高吞吐量,其中个别消息可能偶尔会丢失或无限期延迟? 编辑
我们创建了一个 pull使用 GCP Web GUI 的默认确认截止时间为 10 秒的 PubSub 订阅。原来是我们太乐观了,我们的服务处理一批拉取的消息需要10多秒的时间。该服务不会抛出异常,它实
批处理 pubsub 请求的 NODEJS 示例代码如下所示: // Imports the Google Cloud client library const PubSub = require(`@
在 Google PubSub 中,可以异步调用来自客户端的发布调用。因此,我认为可以同时触发多个发布请求并将其发送到服务器,尤其是在批处理阈值太低的情况下。 如果这是真的,pubsub 客户端如何控
根据堆栈驱动程序图表,我们开始注意到某个主题/订阅的“未确认消息”数量不时增加。 症状 我不知道我们可以信任多少堆栈驱动程序图表,但我已经检查过: 拉取操作数与发布操作数一样多 问题发生时ack操作计
我有一个将数据写入 Google Cloud pubsub 的应用程序,根据 pubsub 的文档,由于重试机制导致的重复是偶尔会发生的事情。还有乱序消息的问题,这在 pubsub 中也不能保证。 另
我有一个包含多个拉取订阅的 pubsub 主题。我想要某种机制,我可以在其中发布带有“优先级”标签的消息,使消息尽可能地跳到队列的前面。 我不需要任何有保证的排序语义,只需要“尽力而为”的优先级机制。
我在我们的平台中集成了 GMB API,并与 PubSub 合作以获取实时评论通知。 为此,我已经完成了以下步骤: Created topic在谷歌 PubSub 云上。 创建了它的 subscrip
试图找出在本地测试 PubSub 推送端点的最佳方法。我们尝试过使用 ngrok.io,但您必须拥有域才能加入白名单(这样做的工具也已损坏……导致无限重定向循环)。我们还尝试在本地模拟 PubSub。
我们希望通过带有 pubsub 触发器 ( https://firebase.google.com/docs/functions/pubsub-events ) 的 firebase 云函数接收有关某
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 2年前关闭。 Improve t
我有一个向 PubSub 主题发布消息的简单服务,偶尔会收到“已超过截止日期”错误消息: GaxError(RPC failed, caused by ) Python代码: from google.
我的应用程序发布少量消息(最多每几秒 1 条)。它不订阅。 首次使用时,PubSub 会创建 60 个永久保持事件状态的线程,如下所示: "grpc-default-worker-ELG-1-1 Id
我想检查运行代码是否有权在特定项目中执行“pubsub.topics.list”。这段代码: try (TopicAdminClient admin = getTopicAdmin()) {
我正在开发微博 spring mvc hibernate 应用程序。我需要实现像推特这样的发布订阅功能。 我正在使用 RabbitMQ 通过 Spring AMQP 抽象进行消息传递。 我在网络上到处
我对 Airflow 很陌生,并尝试使用 apache Airflow 与 google pubsub 的集成,我猜它是添加到“Airflow-300”JIRA 下的。如果我在这里阅读不正确,请纠正我
我正在学习 https://www.woolha.com/tutorials/node-js-google-cloud-pub-sub-basic-examples 上的教程并且有一些困难.. 我在
我在我的 .net 核心微服务中使用 DAPR 和 Docker。我在 docker-compose.yml 中进行了以下配置以运行代理和 dapr pubsub 配置。 PUBSUB.yml api
我是一名优秀的程序员,十分优秀!