Logo

dev-resources.site

for different kinds of informations.

Micronaut Pulsar

Published at
12/11/2021
Categories
java
micronaut
pulsar
apachepulsar
Author
_hs_
Author
4 person written this
_hs_
open
Micronaut Pulsar

A while ago I worked with Apache Pulsar and had interest in Micronaut. At the time there was no Micronaut Pulsar integration so I decided to give it a try. It was fun to go through certain Micronaut things and understand how and what to do but more than that I finally could contribute to open source project. Graeme Rocher is quite a nice guy I have to say. I expected more problems regarding coding style or something but it turns out if the tools pass the test you're quite OK with the contribution.

So to try to make it a bit more public I decided to publish a simple blog post about it. You can find the repository here.

What does it do?

It just makes integration between Micronaut framework and Apache Pulsar library. In the background it still uses Apache Pulsar client library for Java. Yes, that means it does still have some reflection usage in the background but I figured it's better to use existing piece of code than to rewrite whole protocol implementation in Java. I did test it against native image using Graal tools so I did some effort into making Pulsar client Java library work with it. It's not the best case scenario but it works so I guess it's good enough until either their library is rewritten to not use reflections or help is provided with rewriting this implementation.

What's supported?

Just the "basics" so to speak. Configuring Apache Pulsar client with TLS, OAuth2, or just setting the local URL. Consumers and producers are the main focus so one could easily annotate classes/interfaces and their methods to consume/send messages. I did replace Pulsars object mapper with Micronaut one so you can rely on the same processing when using JSON, and thanks to Johnas Conrad it's now replaced with new JsonMapper instead of ObjectMapper.

Annotations are made for consumers and producers but readers can have just annotation for injections - they will be automatically created for each injection point.

Protobuf mapping is not tested so the whole module is treated as snapshot - beta. If someone would like to give it a go feel free to fork and play with it. Other than that String, byte, JSON are well tested and working even Kotlin should be fine with suspend marked methods.

I assume anyone interested in this module understand Pulsars approach so I will not detail types of consumers or other things. I will just mention that most of the things are configurable through annotation properties like type of subscription, single topic, regex topic, acknowledgment timeout, and such.

Plans for the future

I wanted to build multi-tenant module which would allow reader, consumer, and producer injection point to detect tenant in context and instantiate or reuse existing one. This however would assume that producers and consumers that are made with annotations require a list in application properties or someplace to boot those consumers and readers during runtime. Otherwise it's not possible given that tenant headers are passed in requests. This would mean that consumers (or producers) would not be instantiated until request is made that would make that tenant known to the application. I think this is not usable so didn't implement it but let me know if you think otherwise.

Because module is in testing phase and I have no idea would be it be used enough I'd rather wait for requests and see where should effort be put it than to make code for something that is not used at all.

So, I'm hoping that this post would make it a bit more public and check interest in this module. If there's any I can get some feedback or maybe even couple of pull requests :D.

Given that I don't use Pulsar or Micronaut in my daily job anymore I don't have too much insights on what could be useful or what is bad so please do feel free to make suggestions or any kind of input.

micronaut Article's
30 articles in total
Favicon
Pub-sub Redis in Micronaut
Favicon
Choosing the Right Java Microservices Framework: Spring Boot, Quarkus, Micronaut, and Beyond
Favicon
Micronaut vs. Spring Boot: A Detailed Comparison
Favicon
[Micronaut] Receiving Japanese(Shift-JIS) data as HTTPResponse
Favicon
[Micronaut] Try Cookie
Favicon
[Micronaut] Generating and downloading files as ZIP or JSON
Favicon
Sending files from Micronaut applications
Favicon
[Micronaut] Receiving multipart/form-data
Favicon
Try Micronaut and Doma2
Favicon
[Micronaut] Accessing SQL Server 2
Favicon
Serving static assets with Micronaut
Favicon
Run a Micronaut application on Tomcat
Favicon
[Micronaut] Accessing SQL Server 3
Favicon
[Micronaut] Accessing SQL Server 1
Favicon
Try Micronaut
Favicon
Adding AI to your Micronaut search service
Favicon
Swagger-Operator, let groovy operate your cluster
Favicon
Jugando con Mono y Flux (de Reactor)
Favicon
Meeting & Mastering Java
Favicon
Integration testing in Micronaut
Favicon
mapping OpenAPI formats
Favicon
Connecting Micronaut to MongoDB database using Kotlin
Favicon
🥉 Micronaut: Top 5 Server-Side Frameworks for Kotlin in 2022
Favicon
AWS Lambda SnapStart - Part 2 Measuring Java 11 Lambda cold starts with Micronaut framework
Favicon
Integration Tests with Micronaut and Kotlin
Favicon
Mapping with SCHEMA
Favicon
annotation mapping & bean-validation
Favicon
Can Micronaut replace Spring Boot? Let's take a look at an example.
Favicon
Cloud Native Java: Integrating YugabyteDB with Spring Boot, Quarkus, and Micronaut
Favicon
Micronaut Pulsar

Featured ones: