当前位置: 首页 > news >正文

长春平原网站建设淮安市建设局网站

长春平原网站建设,淮安市建设局网站,网站建设需求模版,wordpress主题开发书籍发布/订阅是GCP提供的不错的工具。 它非常方便#xff0c;可以帮助您解决应用程序可能面临的消息传递难题。 实际上#xff0c;如果您使用GCP#xff0c;则可以使用托管消息解决方案。 如预期的那样#xff0c;使用实际的发布/订阅解决方案需要一定的配额#xff0c;因此… 发布/订阅是GCP提供的不错的工具。 它非常方便可以帮助您解决应用程序可能面临的消息传递难题。 实际上如果您使用GCP则可以使用托管消息解决方案。 如预期的那样使用实际的发布/订阅解决方案需要一定的配额因此对于 开发中必须使用不会花钱的东西。 在这些情况下您可以使用Pub / Sub 仿真器 。 要开始使用模拟器您需要先安装它 gcloud components install pubsub-emulator 确实很方便但是具有docker映像因为它更便于携带。 不幸的是没有来自Google Cloud的官方图片但是您可以使用Docker Hub上可用的解决方案之一。 现在运行它 gcloud beta emulators pubsub start --project test -project 之后您的应用程序可以连接到发布/订阅模拟器。 默认端口为8085 我将以Java单元测试为例。 package org.gkatzioura.pubsub; import java.io.IOException; import java.nio.charset.Charset; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.rpc.FixedTransportChannelProvider; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.cloud.pubsub.v1.Publisher; import com.google.cloud.pubsub.v1.SubscriptionAdminClient; import com.google.cloud.pubsub.v1.SubscriptionAdminSettings; import com.google.cloud.pubsub.v1.TopicAdminClient; import com.google.cloud.pubsub.v1.TopicAdminSettings; import com.google.cloud.pubsub.v1.stub.GrpcSubscriberStub; import com.google.cloud.pubsub.v1.stub.SubscriberStub; import com.google.cloud.pubsub.v1.stub.SubscriberStubSettings; import com.google.protobuf.ByteString; import com.google.pubsub.v1.ProjectSubscriptionName; import com.google.pubsub.v1.ProjectTopicName; import com.google.pubsub.v1.PubsubMessage; import com.google.pubsub.v1.PullRequest; import com.google.pubsub.v1.PullResponse; import com.google.pubsub.v1.PushConfig; import com.google.pubsub.v1.Subscription; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; public class LocalPubSubTest { private static final String PROJECT test-project ; private static final String SUBSCRIPTION_NAME SUBSCRIBER ; private static final String TOPIC_NAME test-topic-id ; private static final String hostPort 127.0.0.1:8085 ; private ManagedChannel channel; private TransportChannelProvider channelProvider; private TopicAdminClient topicAdmin; private Publisher publisher; private SubscriberStub subscriberStub; private SubscriptionAdminClient subscriptionAdminClient; private ProjectTopicName topicName ProjectTopicName.of(PROJECT, TOPIC_NAME); private ProjectSubscriptionName subscriptionName ProjectSubscriptionName.of(PROJECT, SUBSCRIPTION_NAME); private Subscription subscription; Before public void setUp() throws Exception { channel ManagedChannelBuilder.forTarget(hostPort).usePlaintext().build(); channelProvider FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); CredentialsProvider credentialsProvider NoCredentialsProvider.create(); topicAdmin createTopicAdmin(credentialsProvider); topicAdmin.createTopic(topicName); publisher createPublisher(credentialsProvider); subscriberStub createSubscriberStub(credentialsProvider); subscriptionAdminClient createSubscriptionAdmin(credentialsProvider); subscription subscriptionAdminClient.createSubscription(subscriptionName, topicName, PushConfig.getDefaultInstance(), 0); } After public void tearDown() throws Exception { topicAdmin.deleteTopic(topicName); subscriptionAdminClient.deleteSubscription(subscription.getName()); channel.shutdownNow(); } Test public void testLocalPubSub() throws Exception { final String messageText text ; PubsubMessage pubsubMessage PubsubMessage.newBuilder() .setData(ByteString.copyFrom(messageText, Charset.defaultCharset())) .build(); publisher.publish(pubsubMessage).get(); PullRequest pullRequest PullRequest.newBuilder() .setMaxMessages(1) .setReturnImmediately( true ) // if messages are not available immediately return .setSubscription(subscription.getName()) .build(); PullResponse pullResponse subscriberStub.pullCallable().call(pullRequest); String receiveMessageText pullResponse.getReceivedMessages(0).getMessage().getData().toStringUtf8(); Assert.assertEquals(messageText, receiveMessageText); } private TopicAdminClient createTopicAdmin(CredentialsProvider credentialsProvider) throws IOException { return TopicAdminClient.create( TopicAdminSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(credentialsProvider) .build() ); } private SubscriptionAdminClient createSubscriptionAdmin(CredentialsProvider credentialsProvider) throws IOException { SubscriptionAdminSettings subscriptionAdminSettings SubscriptionAdminSettings.newBuilder() .setCredentialsProvider(credentialsProvider) .setTransportChannelProvider(channelProvider) .build(); return SubscriptionAdminClient.create(subscriptionAdminSettings); } private Publisher createPublisher(CredentialsProvider credentialsProvider) throws IOException { return Publisher.newBuilder(topicName) .setChannelProvider(channelProvider) .setCredentialsProvider(credentialsProvider) .build(); } private SubscriberStub createSubscriberStub(CredentialsProvider credentialsProvider) throws IOException { SubscriberStubSettings subscriberStubSettings SubscriberStubSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(credentialsProvider) .build(); return GrpcSubscriberStub.create(subscriberStubSettings); } } 而已。 现在您可以进行一些具有成本效益的单元测试 翻译自: https://www.javacodegeeks.com/2019/09/pub-sub-local-emulator.html
http://www.pierceye.com/news/454828/

相关文章:

  • wordpress 网站暂停做社区生意的网站
  • 渭南做网站的公司商业网站后缀名
  • 凡科建站电话邙山网站建设
  • 哪些网站可以做ppi小程序源码什么意思
  • 做公司网站都需要哪些东西产品画册设计公司
  • 网页优化与网站优西安开发网站建设
  • 大连建设监察执法网站免费icp备案服务码
  • 潮州做网站京东网站建设步骤
  • 遂宁模板建站公司懂福溶州做戒网站
  • 百度网站下拉排名农村电商平台发展现状
  • 移动端网站开发与网页开发区别wordpress首页文章显示
  • 有什么网站是layui做的wordpress 微信咨询菜单
  • 湖南网站seo营销x cache wordpress
  • 网站建设太金手指六六十八知名网站建设推荐
  • WordPress找不到站点做好评做销量的网站
  • 网站建设项目经历东莞市官网网站建设企业
  • FileZilla做网站程序开发的难点
  • 网站开发前端制作网站flsh怎么做
  • 建设网站需申请什么手续如何申请公司名称注册
  • 中山网站制无锡公司建立网站
  • 优化推广网站网站建设的岗位职责
  • 网站建设制作设计优化兰州如何用织梦建网站
  • wordpress 网站禁用全屏代码百度怎么建设网站
  • 强军网网站建设北京各大网站推广服务公司
  • 西安优秀的集团门户网站建设公司网站建设中 优秀账户的标准
  • 网站建设的对比分析移动设备网站开发注意点
  • 在word上怎么做网站链接网站开发试题
  • 自己做网站新手入门淮北论坛招聘网
  • 建网站的意义大学跳蚤市场网站建设
  • 平阳做网站成都网站优化公司哪家好