lyra
lyra copied to clipboard
Add Jackson annotations to be able to configure via JSON
I'm looking to use Lyra in the RabbitMQ integration of Druid (http://druid.io/). Druid uses Jackson (https://github.com/FasterXML/jackson) and it would greatly simplify the integration of Lyra if it did as well.
I'm looking into creating a pull request with this feature, but I'm new to Jackson so it may take some time. Any pointers and help would be greatly appreciated.
Makes perfect sense. I was trying to do something similar to this. The developer can just declare the hierarchy of connection, channel and associated exchanges and queues in an xml or json format and have the Config and ConnectionOptions generated out of it.
Feel free to post a better idea of what you think this should look like. My initial thought is that while this sounds cool, it might be out of scope for what Lyra is intended to be. I'd also be hesitant to add Jackson as a Lyra dependency (though there are workarounds for this).
Agree that this is not what Lyra was intended to be. Sometimes, having a lot of dependencies will deter the users from using it. This could as well be a separate wrapper library over Lyra.
If it so turns out that the wrapper library is not too heavy (few classes) we could merge it in. To reduce the dependency set, we could use JAXB (xml support) or just use Jackson as an optional maven dependency.
Well, I'm hoping that simply annotating the config classes correctly will enable this functionality. It's not a matter of implementing any code, but to provide Jackson with enough information so that it's able to instantiate the Lyra config from a JSON string.
The cool part is that the annotations do not add a runtime dependency on Jackson, you can run Lyra exactly as before but if you have a system that uses Jackson, it will be able to instantiate Lyra via JSON config files. There is an added dependency in maven but the scope for that is "provided" (and another one for testing only).
I've started my journey and I hope it won't be too long until I have something to show for it. I really hope you'll give it a chance. Having a wrapper library would "work" but it would be very hackish and error prone since most of the config classes in Lyra would have to be overridden for the sole purpose of adding the needed annotations.
Here is my first commit: https://github.com/activitystream/lyra/commit/d34a4de332e91b415c3ff9076485324dd54ce0fc
Basically this enables the Duration class to be instantiated with a JSON file as you can see in the test case.
You could probably also use a custom Jackson deserializer that calls Duration.of
to instantiate Duration objects.