Apache Felix Event Admin在ServiceMix容器下使用
来源:互联网 发布:java 引号转义 编辑:程序博客网 时间:2024/06/04 18:04
1、首先在pom文件中引用
<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"); }}
0 0
- Apache Felix Event Admin在ServiceMix容器下使用
- 在servicemix下,使用hibernate操作数据库
- Apache Felix
- 在Apache Felix中运行bundle
- 在Eclipse中搭建Apache Felix环境
- 使用 Apache ServiceMix 作为 Healthcare Service Bus
- 在jdk8环境下使用dubbo-admin
- Apache ServiceMix-002-ServiceMix是什么
- 在Servicemix中如何使用Quartz组件
- 使用maven,Apache ServiceMix开发OSGI web例子
- OSGI--apache felix 入门
- Apache Felix HTTP Service
- apache-felix实例
- Apache ServiceMix 介绍
- Apache ServiceMix 介绍
- Apache ServiceMix 介绍
- Apache ServiceMix 介绍
- Apache ServiceMix 初探
- 构建微服务-第一章-什么是微服务_007其他功能分解技术
- Android使用mvp模式入门
- FloatingActionButton的使用
- Android NDK环境配置
- 链接字符串各属性介绍
- Apache Felix Event Admin在ServiceMix容器下使用
- leetcode--Linked List Cycle II
- 构建微服务-第一章-什么是微服务_008总结
- ZOJ3229:Shoot the Bullet 有源汇上下界最大流
- Log4j 配置详解
- three.js制作一个立体几何体
- Windows10下搭建React Native Android开发环境
- android inflater 用法
- Snackbar的使用