npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generator-jhipster-kafka

v1.0.1

Published

A JHipster module that generates Apache Kafka consumers and producers and more!

Downloads

25

Readme

Kafka for JHipster

NPM version Build Status Dependency Status

A JHipster module that generates Apache Kafka consumers and producers and more!

🚦 Done !

🚧 To do or doing...

You can have more details about work in progress in issues:

  • [x] Schema Registry and Avro support
  • [ ] Producer API (ordered messages, high throughput...)
  • [ ] Deserialization alternatives (JacksonSerde) as a prompt option
  • [ ] Security (SSL protocol as a prompt option, safe mode...)
  • [ ] JHipster entity sub-generator hook
  • [ ] JHipster microservices applications support
  • [ ] Kafka Connect support
  • [ ] Kafka Streams support

Introduction

This is a JHipster module, that is meant to be used in a JHipster application. You can use it to generate Apache Kafka consumers and producers in a JHipster backend (Spring Boot / Java only supported at the moment). It uses Apache Kafka client as a base.

Kafka module for JHipster in action!

Prerequisites

As this is a JHipster module, we expect you have JHipster and its related tools already installed:

Or just run:

npm i -g generator-jhipster

:warning: If you're using last version of the module or by linking package on master branch you should be using JHipster last version (main branch which is actually wip next release v7). If you want to use JHipster v6 you will have to use v6.x_maintenance branch of this module.

Installation

:warning: Last version of yo (Yeoman) is needed to make it work correctly!

With NPM

To install this module and Yeoman (yo):

npm install -g generator-jhipster-kafka yo

To update this module:

npm update -g generator-jhipster-kafka

With Yarn

To install this module and Yeoman (yo):

yarn global add generator-jhipster-kafka yo

To update this module:

yarn global upgrade generator-jhipster-kafka

Usage

This describes how to use basically this module with a JHipster generated project.

Link local projects

If you want to use local versions of JHipster and the Kafka module:

  1. Go to your generator-jhipster project folder and run npm link
  2. Go to your generator-jhipster-kafka project folder and run npm link
  3. In your project generated with JHipster run npm link generator-jhipster generator-jhipster-kafka

⚠️ If you delete generator-jhipster or generator-jhipster-kafka folder, you will have to repeat the previous steps.

Basic usage

Important : The following steps and use cases are to be done on a single generated JHipster monolithic application.

📅 In a near future it will be achievable between two or more monolithic applications or in microservices.

  1. Ensure you have a JHipster version > 6.0.0 with: jhipster --version
  2. Create a JHipster project in a new folder: mkdir myproject && cd myproject && jhipster (you can also create a backend project only with jhipster --skip-client)
  3. Choose Asynchronous messages using Apache Kafka in server side options when answering the following question : "Which other technologies would you like to use?"
  4. In the same folder, then run yo jhipster-kafka and then follow the use case you need
  5. After the generation have been done, run Kafka with: docker-compose -f src/main/docker/kafka.yml up -d
  6. Run your application with: ./mvnw

The different use cases are listed on another page.

Prompt options tree

Do your own configuration step-by-step!

The END represents the end of the prompts below, when files are written after confirmation (you can use the --force option with yo jhipster-kafka to overwrite all files).

Skip prompts

You can use yo jhipster-kafka --skip-prompts to use the default prompts values to generate:

  • a minimal kafka configuration in application.yml files with only a bootstrap.servers
  • a akhq.yml docker-compose file to run AKHQ (see below)
  • a GenericConsumer.java that you extend to create your own consumers

Test consumers and producers

You can use your producer (*Producer.java) in other layers like resources or services by instancing it and using its send method (which is asynchronous).

By default a *KafkaResource.java is also generated with the producer. It has an endpoint to call the generated producer. Supposing you have generated consumers and producers for an existing Foo JHIpster entity (with a String field foo) and for no entity (Bar prefix), you can test it that way with curl and jq:

token=`curl -X POST localhost:8080/api/authenticate -d '{ "username": "admin", "password": "admin" }' -H "Content-Type: application/json"|jq -r '.id_token'`

# For a producer linked to an entity (Foo as JSON):
curl -H "Authorization: Bearer $token" -H 'Content-Type: application/json' -d '{ "foo": "foo" }' -X POST localhost:8080/api/foos/kafka

# For a producer not linked to an entity (String):
curl -H "Authorization: Bearer $token" -H 'Content-Type: application/json' -d 'bar' -X POST localhost:8080/api/bars/kafka

Generated consumers should not be explicitly used in other classes as each of them is running in a thread listening to the incoming messages. However, messages sent through the generated producer will be read if an associated consumer has been generated as well. You just have to read the logs of ./mvnw locally.

AKHQ

🚀 AKHQ (previously known as KafkaHQ) can be used following those steps in the root directory:

  1. Run docker-compose -f src/main/docker/kafka.yml -f src/main/docker/akhq.yml up -d to launch the ZooKeeper and Kafka services with AKHQ
  2. Go to http://localhost:11817
  3. Start your application with ./mvnw to manage your topics and more!

How to contribute?

If you want to contribute to the module, please read the CONTRIBUTING.md.

In addition, here are some things to know before to dive into:

  • JavaScript ES6 is used for the generator and Java for the generated files
  • The module is a Yeoman generator (the module is a sub-generator of JHipster which is itself a Yeoman-based generator)
  • Module tests are done with mocha, yeoman-assert and yeoman-test. You can run them with npm test
  • Format rules are defined in .eslintrc and .prettierrc
  • generators/app/index.js is the main entrypoint, it uses prompts.js and files.js
  • generators/app/prompts.js is used to manage prompts options
  • generators/app/files.js is used to write files to the generated project
  • generators/app/templates contains ejs templates (.ejs) used to generate files

License

Apache-2.0 © François Delbrayelle (main contributor and stream leader) and all contributors, thank you!