Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use a custom hono http protocol adapter? Is there an example #3448

Open
BanDianMan opened this issue Nov 28, 2022 · 12 comments
Open

How to use a custom hono http protocol adapter? Is there an example #3448

BanDianMan opened this issue Nov 28, 2022 · 12 comments
Labels

Comments

@BanDianMan
Copy link

I saw an explanation on the official website, but I don't know how to use it

https://www.eclipse.org/hono/docs/dev-guide/custom_http_adapter/

@n-deliyski
Copy link
Contributor

At the moment there are there adapters that uses the HTTP Adapter base classes:

They could be used as examples.
All of the them extends AbstractVertxBasedHttpProtocolAdapter.
At root level there is org.eclipse.hono.adapter.<adapter name>.app.Application class that is the start point.
You could take a look at that class at the three adapters.
The major difference between the Http based adapters is that they have different routes. This is the mapping of a HTTP request to a handler.
If you want to build own adapter you could the copy the root classes of Sigfox/HttpAdapter into new sub module and then apply your customizations.

Hope that helps.

@BanDianMan
Copy link
Author

At the moment there are there adapters that uses the HTTP Adapter base classes:

They could be used as examples. All of the them extends AbstractVertxBasedHttpProtocolAdapter. At root level there is org.eclipse.hono.adapter.<adapter name>.app.Application class that is the start point. You could take a look at that class at the three adapters. The major difference between the Http based adapters is that they have different routes. This is the mapping of a HTTP request to a handler. If you want to build own adapter you could the copy the root classes of Sigfox/HttpAdapter into new sub module and then apply your customizations.

Hope that helps.

Thanks for your reply
I currently deploy hono on the server through cloud2edge
I now have a new quarkus project to implement a custom adapter
But I don't know how to configure in the application.properties file
Can I send data to Hono through addRoutes if I am only in the LAN

@n-deliyski
Copy link
Contributor

But I don't know how to configure in the application.properties file

The configuration values for e.g Http adapter are described at https://www.eclipse.org/hono/docs/admin-guide/http-adapter-config/. An example configuration exists inside the integration tests: https://github.com/eclipse-hono/hono/tree/master/tests/src/test/resources/http.

Regarding cloud2edge, you have to extend hono helm chart to deploy the custom adapter. The properties for your custom adapter should be added to https://github.com/eclipse/packages/blob/master/charts/hono/values.yaml

Can I send data to Hono through addRoutes if I am only in the LAN

In general you need LoadBalancer type for your service and then it depends on the your Kubernetes configuration.
For test purposes one easy way to expose the access to your adapter is via kubectl port-forward command.

@BanDianMan
Copy link
Author

但是我不知道如何在应用程序属性文件中配置

例如 Http 适配器的配置值在https://www.eclipse.org/hono/docs/admin-guide/http-adapter-config/ 中描述。集成测试中存在一个示例配置:https://github.com/eclipse-hono/hono/tree/master/tests/src/test/resources/http。

关于 cloud2edge,您必须扩展hono helm chart来部署自定义适配器。应将自定义适配器的属性添加到https://github.com/eclipse/packages/blob/master/charts/hono/values.yaml

如果我只在局域网中,我可以通过addRoutes向Hono发送数据吗?

通常,您需要为服务提供负载均衡器类型,然后这取决于您的 Kubernetes 配置。出于测试目的,公开对适配器的访问的一种简单方法是 viacommand。kubectl port-forward

Thank you , I have another question

I have many devices that use the MQTT protocol, but I cannot set the subject of the data to be sent
How do I send to the Hono MQTT adapter? Do I need to implement a custom MQTT adapter?
Whether it can be configured in the Hono MQTT adapter

@n-deliyski
Copy link
Contributor

The MQTT topic schema at the MQTT Adapter is not configurable. It is specified at https://www.eclipse.org/hono/docs/user-guide/mqtt-adapter/.
If the devices use own MQTT topic structure there are two options:

  1. Implement Protocol Gateway that converts the format. See also this example at hono-extra repo.
  2. Implement custom MQTT adapter.

The chosen approach would depend on the use-case and deployment strategy.

@BanDianMan
Copy link
Author

The MQTT topic schema at the MQTT Adapter is not configurable. It is specified at https://www.eclipse.org/hono/docs/user-guide/mqtt-adapter/. If the devices use own MQTT topic structure there are two options:

  1. Implement Protocol Gateway that converts the format. See also this example at hono-extra repo.
  2. Implement custom MQTT adapter.

The chosen approach would depend on the use-case and deployment strategy.

Hello, I have written a gateway through the demo on hono extra
However, I see that the AMQP configuration on 'ClientConfigProperties' is connected to only one device
What should I do if I want to dynamically change Hono's device when connecting to the gateway

@n-deliyski
Copy link
Contributor

Hi,

  • The Protocol Gateway application acts as a gateway device that has fixed device id and cannot be changed dynamically.
  • The end devices connecting via the Gateway should be registered inside the Hono Device Registry with via property.

The mechanism is described at https://www.eclipse.org/hono/docs/concepts/connecting-devices/#connecting-via-a-device-gateway and https://www.eclipse.org/hono/docs/concepts/connecting-devices/#connecting-via-a-protocol-gateway

@BanDianMan
Copy link
Author

hi
I don't quite understand.
Can the gateway send data through the via attribute after the device has set the via attribute
The problem I'm facing is that amqpClientConfig in my configuration file only configures the credentials of one device. I don't know how to send them to multiple devices

@BanDianMan
Copy link
Author

Hi,

  • The Protocol Gateway application acts as a gateway device that has fixed device id and cannot be changed dynamically.
  • The end devices connecting via the Gateway should be registered inside the Hono Device Registry with via property.

The mechanism is described at https://www.eclipse.org/hono/docs/concepts/connecting-devices/#connecting-via-a-device-gateway and https://www.eclipse.org/hono/docs/concepts/connecting-devices/#connecting-via-a-protocol-gateway

Hello, I have understood the usage of via attribute
The gateway itself is also registered in hono. When registering other devices, specify the via attribute as the ID of the gateway device
But how dynamic should the established connection be when connecting to the protocol gateway through MQTT?
Suppose that the protocol gateway only exposes a fixed topic, and the device ID is in the message body
How do I send to hono's device?

@n-deliyski
Copy link
Contributor

Hello BanDianMan,
It is the role of Protocol Gateway to convert the incoming data format to the data format of Hono.
The Protocol Gateway could take the device id from the MQTT payload and pass it as part of the Hono topic.
If you use the gateway-template project you have to extend the abstract class AbstractMqttProtocolGateway.
You could also adapt the AbstractMqttProtocolGateway class to fit better your use-case.
For example if the device id is part of the incoming MQTT message payload you have to change https://github.com/eclipse-hono/hono-extras/blob/master/protocol-gateway/mqtt-protocol-gateway-template/src/main/java/org/eclipse/hono/gateway/sdk/mqtt2amqp/AbstractMqttProtocolGateway.java#L535 to retrieve the device id from the payload instead from the context.
Is that what you are asking for?

@BanDianMan
Copy link
Author

Hello BanDianMan, It is the role of Protocol Gateway to convert the incoming data format to the data format of Hono. The Protocol Gateway could take the device id from the MQTT payload and pass it as part of the Hono topic. If you use the gateway-template project you have to extend the abstract class AbstractMqttProtocolGateway. You could also adapt the AbstractMqttProtocolGateway class to fit better your use-case. For example if the device id is part of the incoming MQTT message payload you have to change https://github.com/eclipse-hono/hono-extras/blob/master/protocol-gateway/mqtt-protocol-gateway-template/src/main/java/org/eclipse/hono/gateway/sdk/mqtt2amqp/AbstractMqttProtocolGateway.java#L535 to retrieve the device id from the payload instead from the context. Is that what you are asking for?

Hello, thank you very much for your proposal
I have completed the first version of gateway development by inheriting the 'AbstractMqttProtocolGateway' class
And the hono device is obtained from the message body

@sophokles73
Copy link
Contributor

@BanDianMan can we close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants