




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1:SpringAMQP整合一:通过rabbitmqAdmin来交换机,队列,绑 publicConnectionFactoryconnectionFactory()CachingConnectionFactorycachingConnectionFactory=newCachingConnectionFactory();return}{RabbitAdminrabbitAdmin=newRabbitAdmin(connectionFactory);return}publicvoidtestRabbitAdmin() //rabbitAdmin.declareBinding(newBinding("temp.queue.direct",Binding.DestinationType.QUEUE,"temp.direct","terabbitAdmin.declareBinding(newBinding("temp.queue.topic",Binding.DestinationType.QUEUE,"temp.topic","temrabbitAdmin.declareBinding(newBinding("temp.queue.fanout",Binding.DestinationType.QUEUE,"temp.fanout","}@parampublicRabbitTemterabbitTemte(ConnectionFactory{RabbitTemterabbitTemte=newRabbitTemte(connectionFactory);returnrabbitTemte;}publicDirectExchangedirectExchange()returnnew}publicTopicExchangetopicExchange()returnnew}publicFanoutExchangefanoutExchange()returnnew}*队publicQueuequeue001()returnnew}publicQueuequeue002()returnnew}publicQueuequeue003()returnnew}队列二绑定到DirectExchangepublicBindingqueue002BindingDirectExchange()return}*DirectExchangepublicBindingqueue003BindingDirectExchange()return} 交换机绑定二个队列(queue01queue001top.key.*publicBindingqueue001BindingTopicExchange002()return}*publicBindingqueue003BindingTopicExchange()return}queue001publicBindingqueue001BindingFanoutExchange()return}publicBindingqueue002BindingFanoutExchange001()returnpublicvoidtestRabbitTemteToDirecit()MessagePropertiesmessagePropertiesnewMessageProperties();rabbitTemte.convertAndSend("directExchange001","direct.key.key1",message);}publicvoidtestRabbitTemteToTopic()MessagePropertiesmessagePropertiesnewMessageProperties();Messagemessage=newMessage("测试rabbitmqTem{publicMessagepostProcessMessage(Messagemessage)throwsSystem.out.println("调用MessagePostProcessor处理消息");returnmessage;}}publicvoidtestRabbitTem}二:SimpleMessageListenerContrinerpublicSimpleMessageListenerContainersimpleMessageListenerContainer()SimpleMessageListenerContainermessageListenerContainer=new{publicStringcreateConsumerTag(Stringqueue)returnqueue+":"+queue.hashCode()+}{publicvoidonMessage(Messagemessage,Channelchannel)throwsSystem.out.println("消费的消息:"+new}return}三.SimpleMessageListenerContainer通过设置messageAdapter来设置消息消费者{SimpleMessageListenerContainermessageListenerContainer=newpublicStringcreateConsumerTag(Stringqueue)returnqueue+":"+queue.hashCode()+}MessageListenerAdaptermessageListenerAdapter=newMessageListenerAdapter(newreturnmessageListenerContainer;}publicclassMessageDelegatepublicvoidhandleMessage(byte[]bodys)}publicvoidhandleMessage(String} publicvoidconsumerMsg(byte[]bodys) publicvoidconsumerMsg(String{publicclassTextMessageConverterimplements{publicMessagetoMessage(Objectobject,MessagePropertiesmessageProperties)throwsMessageConversionExceptionreturnnewMessage(object.toString().getBytes(),messageProperties);}publicObjectfromMessage(Messagemessage)throws{if(message.getMessageProperties().getContentType().contains("text")){returnnewString(message.getBody());}return}}}spring.rabbitmq.publisher-confirms=true生产端开启确认功能 {rabbitTemte.setConfirmCallback(angleConfirmCallBack);rabbitTemte.setReturnCallback(angleReturnCallBack);Messagemessage=StringmsgId=UUID.randomUUID().toString();CorrelationDatacorrelationDatanewCorrelationData(msgId);}publicclassAngleConfirmCallBackimplementsRabbitTem{publicvoidconfirm(CorrelationDatacorrelationData,booleanack,String if(!ack)}}}publicclassAngleReturnCallBackimplementsRabbitTem{publicvoidreturnedMessage(Messagemessage,intreplyCode,StringreplyText,Stringexchange,String{System.out.println("message:"+message);}}}publicQueue{returnnew}publicQueue{returnnew}publicTopicExchange{returnnew}publicBindingbinding()return}publicBindingbinding2()return}}@RabbitListener(queues=publicvoidmsgConsumer(Messagemessage,Channelchannel)throwsLongdeliveryTag=(Long)message.getHeaders().get(AmqpHeaders.DELIVERY_TAG);}@RabbitListener(queues=publicvoidmsgConsumer2(@PayloadOrderorderChannelchannel@HeadersMap<String,Objectheaders)throwsILongdeliveryTag=(Long)headers.get(AmqpHeaders.DELIVERY_TAG);}}publicclassRabbitReceiver@RabbitListener(bindings=@QueueBinding(value=@Queue(value="queue-1",durable="true"),exchange=@Exchange(value="exchange-1",type="topic",key="springboot.*"))publicvoidonMessage(Messagemessage,Channelchannel)throws{System.err.println("消费端Payload
channel.basicAck(deliveryTagfalse);}*@param@param@param@throws@RabbitListener(bindings=value=@Queue(value="${}",exchange=@Exchange(value="
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2023届四川省绵阳市高三第二次诊断性考试(二模)理综生物无答案
- 急性有机磷农药中毒治疗
- 复杂肠癌外科治疗体会
- 2025-2030中国短裙行业市场全景调研及投资价值评估咨询报告
- 抑郁症的用药物治疗
- 政治生活 第四单元知识点
- 大学生职业规划大赛《生物科学专业》生涯发展展示
- 2025年中国硬膜防锈剂数据监测报告
- 生产线自动化控制精度方案
- 跨部门协作加速业务迭代进程探讨
- 《关于加强中小学地方课程和校本课程建设与管理的意见》专题培训
- 2025年中考物理押题猜想卷(苏州卷)(全解全析)
- 《半导体行业发展历程》课件
- 新能源开发知识培训课件
- 精神科患者冲动伤人应急演练
- 《煤矿典型事故案例分析》培训课件2025
- 《儿童保健学绪论》课件
- 考研班培训合同范例
- DB45T 2157-2020 食品小作坊生产加工通 用卫生规范
- 游戏公司游戏社区及玩家互动平台建设
- 《电力人工智能自然语言处理模型评价规范》
评论
0/150
提交评论