首页 文章 精选 留言 我的

精选列表

搜索[微服务与微计算],共10000篇文章
优秀的个人博客,低调大师

ActiveMQ 与spring 整合的实例

该整合实例是在maven项目中整合,先要构建一个maven项目 第一步在maven项目的pom.xml文件中导入依赖 <!--这些依赖都是activemq和spring整合需要的依赖--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> </dependency> <!--xbean如<amq:connectionFactory/>--> <dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-spring</artifactId> <version>3.16</version> </dependency> <!--activemq--> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-core</artifactId> <version>5.7.0</version> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> </dependency> 第二步,在spring的core配置文件中配置 <!--接收和发送的配置是一样的--> <?xmlversion="1.0"encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:p="http://www.springframework.org/schema/p"xmlns:task="http://www.springframework.org/schema/task"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:amq="http://activemq.apache.org/schema/core"xmlns:jms="http://www.springframework.org/schema/jms" xsi:schemaLocation=" http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/jmshttp://www.springframework.org/schema/jms/spring-jms.xsd http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd"> <!--配置连接工厂--> <amq:connectionFactoryid="activeConnectionFactory"brokerURL="tcp://127.0.0.1:61616"userName="admin"password="admin"/> <beanid="connectionFactory"class="org.springframework.jms.connection.CachingConnectionFactory"> <constructor-argref="activeConnectionFactory"/> <propertyname="sessionCacheSize"value="100"/> </bean> <!--配置目的地--> <beanid="queueDestination"class="org.apache.activemq.command.ActiveMQQueue"> <constructor-argindex="0"value="FirstQueue"/> </bean> <!--配置JmsTemplate--> <beanid="JmsTemplate"class="org.springframework.jms.core.JmsTemplate"> <propertyname="connectionFactory"ref="connectionFactory"/> <propertyname="defaultDestination"ref="queueDestination"/> <propertyname="receiveTimeout"value="10000"/> <!--true是topic,false是queue,默认是false,此处显示写出false--> <propertyname="pubSubDomain"value="false"/> </bean> </beans> 第三步、使用junit测试 //消息发送 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(value="classpath:/spring/spring-core.xml") publicclassSender{ @Resource(name="JmsTemplate") privateJmsTemplatejmsTemplate; @Test publicvoidtest(){ System.out.println(jmsTemplate); System.out.println("向"+jmsTemplate.getDefaultDestination().toString()+"发送消息"); jmsTemplate.send(newMessageCreator(){ @Override publicMessagecreateMessage(Sessionsession)throwsJMSException{ returnsession.createTextMessage("发送消息"); } }); } } //消息接收 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(value="classpath:/spring/spring-core.xml") publicclassConsumer{ @Resource(name="JmsTemplate") privateJmsTemplatejmsTemplate; @Resource(name="queueDestination") privateDestinationdestination; @Test publicvoidtest(){ System.out.println(jmsTemplate); TextMessagemessage=(TextMessage)jmsTemplate.receive(destination); try{ System.out.println("接受消息>>>>>>>>>>>"+message.getText()); }catch(JMSExceptione){ e.printStackTrace(); } } } 注意:使用MessageListener接收信息的配置 1、实现一个Message监听器 packagecom.web.consumer; importjavax.jms.JMSException; importjavax.jms.Message; importjavax.jms.MessageListener; importjavax.jms.TextMessage; publicclassdemoMessageListenerimplementsMessageListener{ @Override publicvoidonMessage(Messagemessage){ try{ System.out.println("接受到消息>>>>>>>>"+((TextMessage)message).getText()); }catch(JMSExceptione){ e.printStackTrace(); } } } 2、在配置文件中添加如下配置 <beanid="demoMessageListener"class="com.web.consumer.demoMessageListener"/> <beanclass="org.springframework.jms.listener.DefaultMessageListenerContainer"> <propertyname="connectionFactory"ref="connectionFactory"/> <propertyname="destination"ref="queueDestination"/> <propertyname="messageListener"ref="demoMessageListener"/> </bean>

优秀的个人博客,低调大师

Javascrip—proto__与prototype(11)

prototype prototype是一个拥有 [[Construct]] 内部方法的对象才有的属性。例如函数,对象的方法,ES6 中的类。注意 ES6 中的箭头函数没有 [[Construct]] 方法,因此没有prototype这个属性,除非你为它添加一个。 当创建函数时,JavaScript 会为这个函数自动添加prototype属性,这个属性指向的是一个原型对象Functionname.prototype。我们可以向这个原型对象添加属性或对象,甚至可以指向一个现有的对象。 proto 接下来我们说说继承,每个对象都有一个__proto__属性,这个属性是用来标识自己所继承的原型。 注意: JavaScript 中任意对象都有一个内置属性 [[Prototype]] ,在ES5之前没有标准的方法访问这个内置属性,但是大多数浏览器都支持通过__proto__来访问。以下统一使用__proto__来访问 [[Prototype]],在实际开发中是不能这样访问的。 原型链JavaScript 可以通过prototype和__proto__在两个对象之间创建一个关联,使得一个对象就可以通过委托访问另一个对象的属性和函数。 这样的一个关联就是原型链,一个由对象组成的有限对象链,用于实现继承和共享属性。 构造函数创建对象实例JavaScript 函数有两个不同的内部方法:[[Call]] 和 [[Construct]] 。 如果不通过new关键字调用函数,则执行 [[Call]] 函数,从而直接执行代码中的函数体。 当通过new关键字调用函数时,执行的是 [[Construct]] 函数,它负责创建一个实例对象,把实例对象的__proto__属性指向构造函数的prototype来实现继承构造函数prototype的所有属性和方法,将this绑定到实例上,然后再执行函数体。 模拟一个构造函数: function createObject(proto) { if (!(proto === null || typeof proto === "object" || typeof proto === "function"){ throw TypeError('Argument must be an object, or null'); } var obj = new Object(); obj.__proto__ = proto; return obj; } var foo = createObject(Foo.prototype); 至此我们了解了prototype和__proto__的作用,也了解使用构造函数创建对象实例时这两个属性的指向,以下使用一张图来总结一下如何通过prototype和__proto__实现原型链。 从上图我们可以找出foo对象和Foo函数的原型链: foo.__proto__ == Foo.prototype; foo.__proto__.__proto__ == Foo.prototype.__proto__ == Object.prototype; foo.__proto__.__proto__.__proto__ == Foo.prototype.__proto__.__proto__ == Object.prototype.__proto__ == null; Foo.__proto__ == Function.prototype; Foo.__proto__.__proto__ == Function.prototype.__proto__; Foo.__proto__.__proto__.__proto__ == Function.prototype.__proto__.__proto__ == Object.prototype.__proto__ == null; 构造函数Foo的原型链上没有Foo.prototype,因此无法继承Foo.prototype上的属性和方法。而实例foo的原型链上有Foo.prototype,因此foo可以继承Foo.prototype上的属性和方法。 到这里,我们可以很简单的解答小英童鞋的问题了,在Foo的原型链上没有Foo.prototype,无法继承Foo.prototype上的combineName方法,因此会抛出Foo.combineName is not a function的异常。要想使用combineName方法,可以这样Foo.prototype.combineName.call(this),或者这样this.combineName()(this指向实例对象)。 到此本文结束 这里推荐一下我的前端学习交流群:731771211,里面都是学习前端的,群里会不定期更新最新的教程和学习方法,有想学习web前端的,或是转行,或是大学生,还有工作中想提升自己能力的web前端党欢迎加入。

优秀的个人博客,低调大师

Python L.sort 与sorted

L.sort() Definition : sort(key=None, reverse=False) Type : Function of None module L.sort(key=None, reverse=False) -> None -- stable sort IN PLACE sorted() Definition : sorted(iterable, *, key=None, reverse=False) Type : Function of builtins module Return a NEW sorted list from the items in iterable. *key* specifies a function of one argument that is used to extract a comparison key from each list element: key=str.lower. The default value is None (compare the elements directly). *reverse* is a boolean value. If set to True, then the list elements are sorted as if each comparison were reversed. L.sort()是对L进行就地排序,只适用于列表。 sorted()会新建列表,适用于可迭代对象。 默认升序排列。

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册