NGSI和ContextBroker通信的Java客户端实现

时间:2015-06-02 11:17:14

标签: fiware fiware-orion

为了不重新发明轮子,我正在寻找一些现有的库,用于从Java代码连接到Orion Context Broker。

我发现在fiware.org发布了示例代码,但我不喜欢它,因为它不会隐藏原始XML使用情况。

我还在github

找到了一些代码

有些人似乎有worked on it,但我找不到来源。

是否有一些开放的图书馆成为它的热门参考? API干净,易于使用和隐藏低级别的东西? (XML解析,NGSI通信,REST等)

1 个答案:

答案 0 :(得分:2)

We have build a NGSI V1 (JSON only) client library for the Fiware-Cepheus project.

In your pom.xml:

<dependency>
    <groupId>com.orange.cepheus</groupId>
    <artifactId>cepheus-ngsi</artifactId>
    <version>4.4.3-SNAPSHOT</version>
</dependency>

In your code :

@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 */ });

This library is still under development (available as SNAPSHOT only on the Sonatype repository) and is not considered stable yet, but is fully tested.

It is missing support for many NGSI9 requests, but if your main use is NGSI10, you should be covered.