# JRuby Support
!!! warning "JRuby Support Is a Work in Progress and Not Yet Ready"
Karafka support for JRuby is a work in progress. It is not ready for use until this notice is removed from this page.
This page lists what you need to run Karafka and WaterDrop on JRuby, the limits that apply there, and the state of the Web UI. The target is JRuby 10.0, which is compatible with Ruby 3.4. Older JRuby versions are not a target. JRuby fixes land in the current releases of the gems. See the [Karafka](https://karafka.io/docs/Infrastructure-JRuby-Support/Changelog-Karafka.md) and [WaterDrop](https://karafka.io/docs/Infrastructure-JRuby-Support/Changelog-WaterDrop.md) changelogs for details.
!!! warning "The Web UI Is Not Ready for JRuby"
The Web UI is not ready for use on JRuby.
## JRuby Support / JRuby Versions
Use JRuby 10.0.8.0 or a newer 10.0 release. Older JRuby 10.0 releases have a lock bug: see [Do Not Wrap Producer Calls in `Timeout`](#do-not-wrap-producer-calls-in-timeout).
JRuby 10.1.3.0 does not work: WaterDrop and Karafka cannot start on it until [jruby/jruby#10026](https://github.com/jruby/jruby/issues/10026) is fixed. A regression in this JRuby release makes WaterDrop raise `ArgumentError: wrong number of arguments (given 1, expected 0)` when it sets up a producer, and Karafka sets up a WaterDrop producer when it starts.
## JRuby Support / Installation
Karafka and WaterDrop use librdkafka. On JRuby, there is no precompiled librdkafka, so `gem install` and `bundle install` compile it from source when they install Karafka or WaterDrop. The machine that installs the gems needs:
- A C and C++ compiler and `make`, for example the `build-essential` package on Debian and Ubuntu.
- The OpenSSL development headers, for example `libssl-dev`. Without them, the build succeeds, but librdkafka has no SSL, SASL SCRAM or SASL OAUTHBEARER support, and connections that use them fail.
- The SASL development headers, for example `libsasl2-dev`, if you use SASL GSSAPI (Kerberos).
The Ubuntu images of GitHub Actions have the compilers, `make` and the OpenSSL headers. See [Native Extensions](https://karafka.io/docs/Infrastructure-JRuby-Support/Development-Native-Extensions.md#source-compilation-fallback) for more about source compilation.
## JRuby Support / Process Model
JRuby has no `Process.fork`. Swarm Mode forks its nodes, so it does not run on JRuby: `karafka swarm` fails at boot. Use `karafka server`. It runs one process with many threads, and these threads run in parallel because JRuby has no GVL. See [Swarm / Multi Process](https://karafka.io/docs/Infrastructure-JRuby-Support/Infrastructure-Swarm-Multi-Process.md) for details.
Puma cluster mode (`workers`) also forks, so it does not run on JRuby: Puma stops at boot with `ERROR: worker mode not supported on jruby on this platform`. To [embed Karafka](https://karafka.io/docs/Infrastructure-JRuby-Support/Infrastructure-Embedding.md) in Puma on JRuby, run Puma in single mode.
## JRuby Support / Rails Commands and Consoles
On JRuby 10.0, the Rails commands of apps that load the `prism` gem before Karafka fail with `LoadError: cannot load such file -- .../waterdrop/clients`. Rails 8.1 and Rails 8.0 apps do this by default:
| Command |
JRuby 10.0 |
bundle exec karafka server |
Works |
bin/rails runner |
Fails |
bin/rails server |
Fails |
bundle exec rails console |
Fails |
bundle exec karafka console |
Fails |
In a Rails app, `karafka console` runs `bundle exec rails console`, so it fails the same way. Outside Rails, `karafka console` fails with the same error, because irb loads the `prism` gem. The workaround below is checked for Rails apps only. On JRuby, a console takes much longer to start than on MRI, from seconds to tens of seconds.
Rails loads `prism` when `config/application.rb` requires the Rails frameworks, before `Bundler.require` loads Karafka: Action View loads it on Rails 8.1, and the test_unit railtie loads it on Rails 8.0. A Rails 8.0 app without the test_unit railtie (`rails new --skip-test`) is not affected. `karafka server` works, because `bin/karafka` loads Karafka, Zeitwerk and WaterDrop before the Rails app.
To run the Rails commands on JRuby 10.0, load Zeitwerk before Rails. Set `RUBYOPT`:
```shell
RUBYOPT=-rzeitwerk bin/rails console
```
Or require Zeitwerk in `config/application.rb` before the Rails frameworks:
```ruby
# config/application.rb
require_relative "boot"
# Load Zeitwerk before Rails on JRuby 10.0
require "zeitwerk"
require "rails/all"
```
`require "karafka"` in the same place also works.
This is a JRuby bug, not a Karafka bug. See [jruby/jruby#9589](https://github.com/jruby/jruby/issues/9589).
## JRuby Support / Signals
Stop `karafka server` with `TERM`. On JRuby, `QUIT` prints a JVM thread dump and does not stop the process. See [Signals and States](https://karafka.io/docs/Infrastructure-JRuby-Support/Infrastructure-Signals-and-States.md) for details.
## JRuby Support / Pro Encryption
The `:envelope` mode of [Messages At Rest Encryption](https://karafka.io/docs/Infrastructure-JRuby-Support/Pro-Messages-At-Rest-Encryption.md) works only on MRI, because `jruby-openssl`, the OpenSSL library of JRuby, does not provide `OpenSSL::PKey::RSA#encrypt` and `#decrypt`. The `:direct` mode works on JRuby. JRuby 10.0.8.0 bundles `jruby-openssl` 0.16.3. With it, a `:direct` payload larger than RSA can encrypt (see [Envelope Encryption Mode](https://karafka.io/docs/Infrastructure-JRuby-Support/Pro-Messages-At-Rest-Encryption.md#envelope-encryption-mode)) raises `Java::JavaLang::ArrayIndexOutOfBoundsException` (`too much data for RSA block`). `rescue OpenSSL::OpenSSLError` does not catch this exception. `jruby-openssl` 0.19.4 and later raise `OpenSSL::PKey::RSAError` instead, so add `gem "jruby-openssl", ">= 0.19.4", platforms: :jruby` to your Gemfile.
## JRuby Support / Async and Fiber Scheduler
On JRuby 10.0, `Kernel#sleep`, `ConditionVariable#wait` and `Queue#pop` in a non-blocking fiber do not call the fiber scheduler, so they block the whole thread. With WaterDrop in an Async reactor, each `#produce_sync` and each `DeliveryHandle#wait` blocks all fibers of the reactor until the delivery report arrives. `#produce_async` does not wait for the delivery report, so it does not block the reactor for that time.
This is a JRuby bug, not a Karafka bug. See [jruby/jruby#10027](https://github.com/jruby/jruby/issues/10027), [jruby/jruby#9622](https://github.com/jruby/jruby/issues/9622), [jruby/jruby#9790](https://github.com/jruby/jruby/issues/9790) and [jruby/jruby#9805](https://github.com/jruby/jruby/issues/9805). See [Async Ecosystem Integration](https://karafka.io/docs/Infrastructure-JRuby-Support/WaterDrop-Async-Integration.md) for how WaterDrop works with the fiber scheduler on MRI.
## JRuby Support / Do Not Wrap Producer Calls in `Timeout`
!!! warning "A `Timeout` Around `#produce_sync` or `#produce_async` Can Hang the Producer on JRuby"
On JRuby 10.0.7.0 and older, a `Timeout` or `Thread#raise` that interrupts a thread while it waits for a busy `Mutex` can leave the lock held by that thread. Another thread that needs the same lock then waits forever. If you wrap `#produce_sync` or `#produce_async` in a `Timeout`, the producer can hang. JRuby 10.0.8.0 and MRI do not have this problem.
This is a JRuby bug, not a Karafka bug. See [jruby/jruby#9972](https://github.com/jruby/jruby/issues/9972).
Use the WaterDrop timeouts instead: `max_wait_timeout` and the `message.timeout.ms` setting. See [WaterDrop Configuration](WaterDrop-Configuration.md) for details.
On JRuby 10.0.8.0 and 10.1.3.0, a timed `Queue#pop(timeout:)` or `SizedQueue#push(x, timeout:)` receives `Thread#kill` and `Thread#raise` inside `Thread.handle_interrupt(Object => :never)`. MRI defers both until the block ends. If your code protects cleanup, such as releasing a lock or draining a queue at shutdown, with a `:never` mask and a timed queue call, the cleanup can stop part-way. Karafka and WaterDrop code is not affected. This is a JRuby bug. See [jruby/jruby#10028](https://github.com/jruby/jruby/issues/10028).
---
*Last modified: 2026-11-22 17:38:41*