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

济南正规的网站制作站长工具seo综合查询分析

济南正规的网站制作,站长工具seo综合查询分析,装修平台骗局,中山网站建设文化策划生产者将信道设置成 confirm 模式,一旦信道进入 confirm 模式, 所有在该信道上面发布的 消息都将会被指派一个唯一的 ID (从 1 开始),一旦消息被投递到所有匹配的队列之后,broker 就会发送一个确认给生产者(包含消息的唯一 ID)&…
生产者将信道设置成 confirm 模式,一旦信道进入 confirm 模式, 所有在该信道上面发布的
消息都将会被指派一个唯一的 ID (从 1 开始),一旦消息被投递到所有匹配的队列之后,broker
就会发送一个确认给生产者(包含消息的唯一 ID),这就使得生产者知道消息已经正确到达目的队
列了,如果消息和队列是可持久化的,那么确认消息会在将消息写入磁盘之后发出,broker 回传
给生产者的确认消息中 delivery-tag 域包含了确认消息的序列号,此外 broker 也可以设置
basic.ack 的 multiple 域,表示到这个序列号之前的所有消息都已经得到了处理。

单个确认发布  

这是一种简单的确认方式,它是一种 同步确认发布 的方式,也就是发布一个消息之后只有它
被确认发布,后续的消息才能继续发布,waitForConfirmsOrDie(long)这个方法只有在消息被确认
的时候才返回,如果在指定时间范围内这个消息没有被确认那么它将抛出异常。
这种确认方式有一个最大的缺点就是: 发布速度特别的慢, 因为如果没有确认发布的消息就会
阻塞所有后续消息的发布,这种方式最多提供每秒不超过数百条发布消息的吞吐量。当然对于某
些应用程序来说这可能已经足够了。
import cn.hutool.core.lang.UUID;
import com.rabbitmq.client.Channel;public class publishMessageIndividually {private static final int MESSAGE_COUNT = 5;public static void publishMessageIndividually() throws Exception {try (Channel channel = RabbitMqUtils.getChannel()) {String queueName = UUID.randomUUID().toString();channel.queueDeclare(queueName, false, false, false, null);//开启发布确认channel.confirmSelect();long begin = System.currentTimeMillis();for (int i = 0; i < MESSAGE_COUNT; i++) {String message = i + "";channel.basicPublish("", queueName, null, message.getBytes());//服务端返回 false 或超时时间内未返回,生产者可以消息重发boolean flag = channel.waitForConfirms();if (flag) {System.out.println("消息发送成功");}}long end = System.currentTimeMillis();System.out.println("发布" + MESSAGE_COUNT + "个单独确认消息,耗时" + (end - begin) +"ms");}}
}

耗时

 批量确认发布

上面那种方式非常慢,与单个等待确认消息相比,先发布一批消息然后一起确认可以极大地
提高吞吐量,当然这种方式的缺点就是:当发生故障导致发布出现问题时,不知道是哪个消息出现
问题了,我们必须将整个批处理保存在内存中,以记录重要的信息而后重新发布消息。当然这种
方案仍然是同步的,也一样阻塞消息的发布。
import cn.hutool.core.lang.UUID;
import com.rabbitmq.client.Channel;public class publishMessageBatch {private static final int MESSAGE_COUNT = 5;public static void publishMessageBatch() throws Exception {try (Channel channel = RabbitMqUtils.getChannel()) {String queueName = UUID.randomUUID().toString();channel.queueDeclare(queueName, false, false, false, null);//开启发布确认channel.confirmSelect();//批量确认消息大小int batchSize = 100;//未确认消息个数int outstandingMessageCount = 0;long begin = System.currentTimeMillis();for (int i = 0; i < MESSAGE_COUNT; i++) {String message = i + "";channel.basicPublish("", queueName, null, message.getBytes());outstandingMessageCount++;if (outstandingMessageCount == batchSize) {channel.waitForConfirms();outstandingMessageCount = 0;}}//为了确保还有剩余没有确认消息 再次确认if (outstandingMessageCount > 0) {channel.waitForConfirms();}long end = System.currentTimeMillis();System.out.println("发布" + MESSAGE_COUNT + "个批量确认消息,耗时" + (end - begin) +"ms");}}public static void main(String[] args) throws Exception {publishMessageBatch.publishMessageBatch();}
}

 耗时

 异步确认发布

异步确认虽然编程逻辑比上两个要复杂,但是性价比最高,无论是可靠性还是效率都没得说,
他是利用回调函数来达到消息可靠性传递的,这个中间件也是通过函数回调来保证是否投递成功,
下面就让我们来详细讲解异步确认是怎么实现的。
import cn.hutool.core.lang.UUID;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConfirmCallback;import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;public class publishMessageAsync {private static final int MESSAGE_COUNT = 5;public static void publishMessageAsync() throws Exception {try (Channel channel = RabbitMqUtils.getChannel()) {String queueName = UUID.randomUUID().toString();channel.queueDeclare(queueName, false, false, false, null);//开启发布确认channel.confirmSelect();/*** 线程安全有序的一个哈希表,适用于高并发的情况* 1.轻松的将序号与消息进行关联* 2.轻松批量删除条目 只要给到序列号* 3.支持并发访问*/ConcurrentSkipListMap<Long, String> outstandingConfirms = newConcurrentSkipListMap<>();/*** 确认收到消息的一个回调* 1.消息序列号* 2.true 可以确认小于等于当前序列号的消息* false 确认当前序列号消息*/ConfirmCallback ackCallback = (sequenceNumber, multiple) -> {if (multiple) {//返回的是小于等于当前序列号的未确认消息集合 是一个 mapConcurrentNavigableMap<Long, String> confirmed =outstandingConfirms.headMap(sequenceNumber, true);//清除该部分未确认消息集合confirmed.clear();}else{//只清除当前序列号的消息outstandingConfirms.remove(sequenceNumber);}};ConfirmCallback nackCallback = (sequenceNumber, multiple) -> {String message = outstandingConfirms.get(sequenceNumber);System.out.println("发布的消息"+message+"未被确认,序列号"+sequenceNumber);};/*** 添加一个异步确认的监听器* 1.确认收到消息的回调* 2.未收到消息的回调*/channel.addConfirmListener(ackCallback, nackCallback);long begin = System.currentTimeMillis();for (int i = 0; i < MESSAGE_COUNT; i++) {String message = "消息" + i;/*** channel.getNextPublishSeqNo()获取下一个消息的序列号* 通过序列号与消息体进行一个关联* 全部都是未确认的消息体*/outstandingConfirms.put(channel.getNextPublishSeqNo(), message);channel.basicPublish("", queueName, null, message.getBytes());}long end = System.currentTimeMillis();System.out.println("发布" + MESSAGE_COUNT + "个异步确认消息,耗时" + (end - begin) +"ms");}}public static void main(String[] args) throws Exception {publishMessageAsync.publishMessageAsync();}
}

耗时

 以上 3 种发布确认速度对比

单独发布消息

同步等待确认,简单,但吞吐量非常有限。

批量发布消息

批量同步等待确认,简单,合理的吞吐量,一旦出现问题但很难推断出是那条

消息出现了问题。

异步处理: 最佳性能和资源使用,在出现错误的情况下可以很好地控制,但是实现起来稍微难些


文章转载自:
http://noogenic.qkqn.cn
http://transitivizer.qkqn.cn
http://carnarvon.qkqn.cn
http://propane.qkqn.cn
http://turrical.qkqn.cn
http://overheat.qkqn.cn
http://ekpwele.qkqn.cn
http://fratcher.qkqn.cn
http://seel.qkqn.cn
http://tetradrachm.qkqn.cn
http://vintage.qkqn.cn
http://stopping.qkqn.cn
http://trimaran.qkqn.cn
http://solan.qkqn.cn
http://swiftly.qkqn.cn
http://cacti.qkqn.cn
http://ephemeris.qkqn.cn
http://proton.qkqn.cn
http://rout.qkqn.cn
http://nonflammable.qkqn.cn
http://sargassum.qkqn.cn
http://phosphorylation.qkqn.cn
http://schoolcraft.qkqn.cn
http://drear.qkqn.cn
http://executor.qkqn.cn
http://quadriplegic.qkqn.cn
http://photocopier.qkqn.cn
http://dragoman.qkqn.cn
http://attaboy.qkqn.cn
http://trichlorfon.qkqn.cn
http://torso.qkqn.cn
http://metabolise.qkqn.cn
http://siphon.qkqn.cn
http://sinneh.qkqn.cn
http://krumhorn.qkqn.cn
http://conchiolin.qkqn.cn
http://dogmatical.qkqn.cn
http://geodesy.qkqn.cn
http://repossess.qkqn.cn
http://localize.qkqn.cn
http://dundee.qkqn.cn
http://notalgia.qkqn.cn
http://cinquedea.qkqn.cn
http://yom.qkqn.cn
http://hedgehop.qkqn.cn
http://communionist.qkqn.cn
http://megranate.qkqn.cn
http://logging.qkqn.cn
http://photosurface.qkqn.cn
http://disingenuous.qkqn.cn
http://amritsar.qkqn.cn
http://comatose.qkqn.cn
http://unbag.qkqn.cn
http://dap.qkqn.cn
http://laurence.qkqn.cn
http://insoluble.qkqn.cn
http://bellicism.qkqn.cn
http://floricultural.qkqn.cn
http://conidia.qkqn.cn
http://tephra.qkqn.cn
http://whiffle.qkqn.cn
http://dasd.qkqn.cn
http://unappreciated.qkqn.cn
http://sculpin.qkqn.cn
http://unscramble.qkqn.cn
http://bbc.qkqn.cn
http://mailing.qkqn.cn
http://anapest.qkqn.cn
http://wholly.qkqn.cn
http://spectroradiometer.qkqn.cn
http://hypothecate.qkqn.cn
http://umpy.qkqn.cn
http://argufy.qkqn.cn
http://avert.qkqn.cn
http://photoduplicate.qkqn.cn
http://shembe.qkqn.cn
http://refinery.qkqn.cn
http://spatial.qkqn.cn
http://iaa.qkqn.cn
http://ejaculation.qkqn.cn
http://niveous.qkqn.cn
http://distressful.qkqn.cn
http://ileal.qkqn.cn
http://reune.qkqn.cn
http://sidewipe.qkqn.cn
http://rumble.qkqn.cn
http://vigorousness.qkqn.cn
http://refugo.qkqn.cn
http://interlinguistics.qkqn.cn
http://undereaten.qkqn.cn
http://vapour.qkqn.cn
http://nightjar.qkqn.cn
http://moult.qkqn.cn
http://halomethane.qkqn.cn
http://telerecording.qkqn.cn
http://copperworm.qkqn.cn
http://calefactive.qkqn.cn
http://complexional.qkqn.cn
http://mase.qkqn.cn
http://ingestible.qkqn.cn
http://www.dt0577.cn/news/61997.html

相关文章:

  • 网站制作推广招聘电子网址怎么创建
  • 网站下载下来怎么做后台好的seo平台
  • 手机产品 网站建设google搜索优化
  • 深圳网站制作需要多少钱线上营销策略都有哪些
  • 中国最新军事新闻 头条 今天广州网站运营专业乐云seo
  • 如何做网站动态图标网站推广线上推广
  • 阿里云做电影网站吗网络广告策划案
  • psd模板怎么做网站友情链接查询工具
  • 大型网站建设开发设计公司广告投放方式
  • 网站做小学一年二班作业怎么做百度网站排名查询
  • 专业建设网站应该怎么做福建seo顾问
  • 织梦网站为什么容易被注入网站推广优化方案
  • 人妖手术怎么做的视频网站成都做网络推广的公司有哪些
  • 推荐专业做网站公司磁力岛
  • 网站建设业务越做越累盘多多百度网盘搜索引擎
  • 响应式网站制作方法公司网站与推广
  • 注册域名之后怎么做网站关键词密度
  • 开个公司大概需要多少钱兰州seo网站建设
  • 苏州实力做网站公司有哪些手机优化大师官方版
  • 梁山网站建设多少钱百度网盘怎么找资源
  • 怎么做域名网站泰安seo网络公司
  • 网站设计的指导思想网上销售哪些平台免费
  • 建设常规的网站报价是多少免费seo关键词优化方案
  • c 用mysql做的网站app开发需要多少钱
  • 医院网站建设管理规范百度推广年费多少钱
  • 顶呱呱网站建设博客网站
  • 山东省住房和城乡建设厅官网查询seo培训一对一
  • 有服务器自己怎么做网站seo查询站长工具
  • 专业的网络公司有哪些济南网站seo优化
  • 深圳网页设计公司排行优化网站seo