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

pc端网站自适应代码深深圳市建设局网站

pc端网站自适应代码,深深圳市建设局网站,广州公认的第一富人区,网站怎么换模板Producer发送普通消息的方式 1.同步发送消息 同步消息代表发送端发送消息到broker之后#xff0c;等待消息发送结果后#xff0c;再次发送消息 实现步骤 创建生产端#xff0c;声明在哪个生产组注册NameServer地址构建Message实体#xff0c;指定topic、tag、body启动…Producer发送普通消息的方式 1.同步发送消息 同步消息代表发送端发送消息到broker之后等待消息发送结果后再次发送消息 实现步骤 创建生产端声明在哪个生产组注册NameServer地址构建Message实体指定topic、tag、body启动生产端发送消息 Test public void syncSend() throws MQBrokerException, RemotingException, InterruptedException, MQClientException {// 1.创建生产端声明在哪个生产组DefaultMQProducer producer new DefaultMQProducer(test_group);// 2.注册NameServer地址producer.setNamesrvAddr(NAME_SERVER_ADDR);// 3.构建Message实体指定topic、tag、bodyMessage message new Message(test, hello world.getBytes());// 4.启动生产端producer.start();// 5.发送消息SendResult sendResult producer.send(message);System.out.println(sendResult.getSendStatus()); }2.异步发送消息 异步消息代表发送端发送完消息后会直接返回但是可以注册一个回调函数当broker将消息落盘后回调这个回调函数 实现步骤 创建生产端声明在哪个生产组注册NameServer地址构建Message实体指定topic、tag、body启动生产端发送消息并且实现SendCallback接口 注这里必须等待异步返回否则消费者无法消费成功 Test public void asyncSend() throws RemotingException, InterruptedException, MQClientException {DefaultMQProducer producer new DefaultMQProducer(test_group);producer.setNamesrvAddr(NAME_SERVER_ADDR);Message message new Message(test, tag-a,hello world.getBytes());producer.start();CountDownLatch countDownLatch new CountDownLatch(1);// 发送消息并且实现SendCallback接口producer.send(message, new SendCallback() {Overridepublic void onSuccess(SendResult sendResult) {countDownLatch.countDown();System.out.println(发送成功 sendResult.getSendStatus());}Overridepublic void onException(Throwable e) {countDownLatch.countDown();System.out.println(发送失败 e);}});countDownLatch.await(); }3、发送单向消息 发送方只负责发送消息不等待服务端返回响应且没有回调函数触发即只发送请求不等待应答。此方式发送消息的过程耗时非常短 实现步骤 创建生产端声明在哪个生产组注册NameServer地址构建Message实体指定topic、tag、body启动生产端发送单向消息 Test public void sendOneWay() throws RemotingException, InterruptedException, MQClientException {DefaultMQProducer producer new DefaultMQProducer(test_group);producer.setNamesrvAddr(NAME_SERVER_ADDR);Message message new Message(test,tag-a, hello world.getBytes());producer.start();producer.sendOneway(message); }Producer发送批量消息 在对吞吐率有一定要求的情况下Apache RocketMQ可以将一些消息聚成一批以后进行发送可以增加吞吐率并减少API和网络调用次数。 Test public void sendBatch() throws MQClientException, MQBrokerException, RemotingException, InterruptedException {DefaultMQProducer producer new DefaultMQProducer(test-producer-group);producer.setNamesrvAddr(RocketMQConfig.NAME_SERVER_ADDR);// 构造批量消息ListMessage list new ArrayList();list.add(new Message(RocketMQConfig.TEST_TOPIC, hello world0.getBytes(Charset.defaultCharset())));list.add(new Message(RocketMQConfig.TEST_TOPIC, hello world1.getBytes(Charset.defaultCharset())));list.add(new Message(RocketMQConfig.TEST_TOPIC, hello world2.getBytes(Charset.defaultCharset())));producer.start();// 发送批量消息producer.send(list);producer.shutdown(); }**注**需要注意的是批量消息的大小不能超过 1MiB否则需要自行分割其次同一批 batch 中 topic 必须相同。 Producer发送延迟消息 Producer想要发送延迟消息只要设置Message的DelayTimeLevel属性大于0即可。 RocketMQ无法随意设置延迟消息的延迟时间只能根据延迟级别进行 延迟级别和延迟时间的对应关系 延迟级别延迟时间延迟级别延迟时间11s106min25s117min310s128min430s139min51min1410min62min1520min73min1630min84min171h95min182h Test public void sendDelay() throws Exception {DefaultMQProducer producer new DefaultMQProducer(test-producer-group);producer.setNamesrvAddr(RocketMQConfig.NAME_SERVER_ADDR);producer.start();Message message new Message(RocketMQConfig.TEST_TOPIC, hello world.getBytes(Charset.defaultCharset()));// 设置延迟级别message.setDelayTimeLevel(3);// 发送批量消息SendResult sendResult producer.send(message);System.out.println(sendResult.getSendStatus());producer.shutdown(); }延迟消息的原理 延迟消息并不会直接发送到指定的topic而是发送到一个延迟消息对应的topic中 当延迟消息的时间到达后在将消息发送到指定的topic中 延迟消息投递的流程 producer端设置消息delayLevel延迟级别消息属性DELAY中存储了对应了延时级别 broker端收到消息后判断延时消息延迟级别如果大于0则备份消息原始topicqueueId并将消息topic改为延时消息队列特定topic(SCHEDULE_TOPIC)queueId改为延时级别的delayLevel-1 mq服务端ScheduleMessageService中为每一个延迟级别单独设置一个定时器定时(每隔1秒)拉取对应延迟级别的消费队列 根据消费偏移量offset从commitLog中解析出对应消息 从消息tagsCode中解析出消息应当被投递的时间与当前时间做比较判断是否应该进行投递 若到达了投递时间则构建一个新的消息并从消息属性中恢复出原始的topicqueueId并清除消息延迟属性从新进行消息投递
http://www.hkea.cn/news/14429523/

相关文章:

  • 上犹建设局网站怎么看一个网站是哪个公司做的
  • 网站出现搜索怎么开网店淘宝
  • 中国公路建设行业协会网站上特价锦州网站建设
  • 保定自助建站软件网站建设与开发的收获与体会
  • 长沙服装网站建设微信小程序分销商城
  • 网站引导页怎么做.黄金网站app免费视频大全
  • 高校网站建设汇报做网站一个月工资
  • 手机怎么做淘客网站网站商城网络整合营销
  • 淘宝网站建设策划案从用户旅程角度做网站分析
  • 图片类网站欣赏怎么注册企业邮箱免费注册
  • 网站建设需要哪些必备文件手机网站app制作公司
  • 科研网站怎么建设官方网站搭建要多少钱
  • 黄南州wap网站建设公司网站推广的途径和要点
  • 1元做网站方案江阴企业网站制作
  • 重庆如何做聚政网站网页无法访问此页面怎么办?网页打不开怎么解决
  • 网站发布文章怎么才能让百度收录关键词搜索广告
  • 专门做养老院的网站wordpress 源文件导入
  • 培训网站设计小程序开发制作工具
  • 优秀的电商设计网站有哪些昆明平台网站开发
  • photoshop制作网站海报阿里巴巴推广平台
  • 企业网站自己怎么做石家庄网络公司行业
  • 动态ip上做网站电商货源平台
  • 做网站容易还是编程容易关键词优化方法有什么步骤
  • 网站开发发和后台开发有什么区别品牌建设实施细则
  • 建网站_网站内容怎么做电子政务门户网站建设教训
  • 推广优化公司网站互联网营销师培训班
  • 医院网站实例短视频优化
  • 顺德网站建设服务平台成都活动策划公司
  • 网页设计购物网站建设c2c商城网站建设方案
  • 个人博客网站建设业务盐城公司做网站