问题描述
为了不浪费时间,我正在寻找一些现有的库,用于从Java代码连接到Orion Context Broker.
In order to not reinventing the wheel I am looking for some existing library for connecting to Orion Context Broker from Java code.
我发现在 fiware.org 已发布示例代码,但我不喜欢它,因为它没有隐藏原始XML用法.
I have found that at fiware.org there is published sample code but I do not like it as it does not hide raw XML usage.
我还在 github上找到了一些代码
有些人似乎已经对其进行了的工作,但是我没有找到消息来源.
Some people seems to have worked on it but I did not find the sources.
是否有一些开放库成为它的流行参考?是API干净且易于使用并隐藏低级的东西吗? (XML解析,NGSI通信,REST等)
Is there some open library becoming popular reference on it? being API clean and easy to use and hiding low level things? (XML parsing, NGSI communications, REST, etc.)
推荐答案
我们已经为 Fiware-Cepheus 项目.
在您的pom.xml
中:
<dependency>
<groupId>com.orange.cepheus</groupId>
<artifactId>cepheus-ngsi</artifactId>
<version>4.4.3-SNAPSHOT</version>
</dependency>
在您的代码中:
@Autowired
NgsiClient ngsiClient;
...
// Prepare UpdateContext
UpdateContext updateContext = new UpdateContext(UpdateAction.UPDATE);
ContextElement contextElement = new ContextElement();
contextElement.setEntityId(new EntityId("Room1", "Room", false));
ContextAttribute attr = new ContextAttribute("temp", "double", "20");
contextElement.setContextAttributeList(Collections.singletonList(attr);
updateContext.setContextElements(Collections.singletonList(contextElement));
// Synchronous call
ngsiClient.updateContext("http://broker:port", null, updateContext).get();
// Asynchronous call
ngsiClient.updateContext("http://broker:port", null, updateContext).addCallback(
updateContextResponse -> { /* success response */ },
throwable -> { /* error response */ });
该库仍在开发中(仅在Sonatype信息库中以SNAPSHOT的形式提供),尚未被认为是稳定的,但已经过全面测试.
This library is still under development (available as SNAPSHOT only on the Sonatype repository) and is not considered stable yet, but is fully tested.
它缺少对许多NGSI9请求的支持,但是如果您的主要用途是NGSI10,则应该覆盖.
It is missing support for many NGSI9 requests, but if your main use is NGSI10, you should be covered.
这篇关于NGSI和ContextBroker通信的Java客户端实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!