Apache Felix Event Admin在ServiceMix容器下使用
2016-03-05 14:44
489 查看
1、首先在pom文件中引用
2、在blueprint文件下引入Event服务,才可以将消息推送到Event里面
3、将服务注入到Bean里面使用
blueprint注入服务
4、当做一个服务发布出去,需要用到的地方,引用服务就可以
创建一个接口类:
创建一个实现类:
blueprint中发布服务
5、从Event里面拿出内容
<dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.service.event</artifactId> <version>1.3.1</version> <type>jar</type> </dependency>
2、在blueprint文件下引入Event服务,才可以将消息推送到Event里面
<reference id="EventAdmin" interface="org.osgi.service.event.EventAdmin" availability="mandatory"/>
3、将服务注入到Bean里面使用
public class EventAdminUtils{ private EventAdmin eventAdmin; public EventAdmin getEventAdmin() { return eventAdmin; } public void setEventAdmin(EventAdmin eventAdmin) { this.eventAdmin = eventAdmin; } public boolean SyncEvent(String topic, Dictionary props) { Event reportGeneratedEvent = new Event(topic,props); eventAdmin.sendEvent(reportGeneratedEvent); return true; } public boolean AsyncEvent(String topic, Dictionary props) { Event reportGeneratedEvent = new Event(topic,props); eventAdmin.postEvent(reportGeneratedEvent); return true; } }
blueprint注入服务
<bean id="adminEvent" class="com.test.event.impl.utils"> <property name="eventAdmin" ref="EventAdmin"/> </bean>
4、当做一个服务发布出去,需要用到的地方,引用服务就可以
创建一个接口类:
public interface IEventAdminUtils { public boolean SyncEvent(String topic,Dictionary props); public boolean AsyncEvent(String topic,Dictionary props); }
创建一个实现类:
public class EventAdminUtils implements IEventAdminUtils{ private EventAdmin eventAdmin; public EventAdmin getEventAdmin() { return eventAdmin; } public void setEventAdmin(EventAdmin eventAdmin) { this.eventAdmin = eventAdmin; } public boolean SyncEvent(String topic, Dictionary props) { Event reportGeneratedEvent = new Event(topic,props); eventAdmin.sendEvent(reportGeneratedEvent); return true; } public boolean AsyncEvent(String topic, Dictionary props) { Event reportGeneratedEvent = new Event(topic,props); eventAdmin.postEvent(reportGeneratedEvent); return true; } }
blueprint中发布服务
<service ref="Sender" interface="com.test.event.utils.IEventAdminUtils"> </service>
5、从Event里面拿出内容
public class Handler implements EventHandler { @Override public void handleEvent(Event event) { String reportMsg = (String) event.getProperty("message"); } }
相关文章推荐
- apache的三种虚拟主机应用场景!!!
- Apache Maven 入门篇
- 如何查看 apahce 已经加在的模块
- Apache的三种MPM模式比较:prefork,worker,event
- Caused by: Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.
- SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-005- 使用ApacheTiles(TilesConfigurer、TilesViewResolver、<put-attribute>、<t:insertAttribute>)
- org.apache.commons.collections.CollectionUtils
- Apache自签ssl证书
- 一个LRUMap的实现——来自apache common-collections框架
- apache2.4配置php5.6.19出现“Cannot load F:/php5.6.19/php5apache2_4.dll into server”错误
- apache 连接数
- apache2 在ubuntu上的文件路径与常用命令
- Ubuntu下安装和配置Apache2
- apache mod_concatx模块 合并多个js/css 提高网页加载速度
- apache实现虚拟主机
- php安装后检测不成功,apache无法解析php
- java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
- 使用Apache ab工具对Apache服务器进行简单的压力测试
- 04_Apache Hadoop 生态系统
- php7+apache2.4 (Windows7下)安装