同じTomcatでJavaWARファイルとJRubyWARファイルを実行するハイブリッドWebアプリケーションがあります。
(JRuby)Resqueをジョブキューとして使用することにしました。ジョブをエンキューするための呼び出しは次のようになります。
Resque.enqueue(FooWorker, 111)
ここで、FooWorkerは、JRuby側で定義および使用される(およびJRuby WARファイルに含まれる)ワーカークラスであり、キューからジョブを処理するときにJRubyResquerakeタスクによって呼び出されます。
FooWorker
Javaコードに、JRubyクラスで処理されるResqueキューにタスクをエンキューする機能を提供したいと思います。
https://github.com/tc/call-jruby-from-java-exampleでTommyChengのコードを確認しました。
//JavaInterfaceExample.java
interface JavaInterfaceExample{
int add(int a, int b);
}
#JrubyAdderImpl.rb
require 'java'
class JrubyAdderImpl
include Java::JavaInterfaceExample
java_signature 'int add(int, int)'
def add(a, b)
a+b
end
end
私のコードは次のようになると思います。
//ResqueInterfaceExample.java
interface ResqueInterfaceExample{
int resque_enqueue_foojob(int a);
}
#JrubyResqueImpl.rb
require 'java'
require 'resque'
class JrubyResqueImpl
include Java::ResqueInterfaceExample
java_signature 'int resque_enqueue_foojob(int)'
def resque_enqueue_foojob(a)
Resque.enqueue(FooWorker, a)
end
end
私FooWorker
のクラスはRailsアプリの展開されたwarファイルディレクトリにあり、ファイルはapp/workers/foo_worker.rb
FooWorker
コードを正しくコンパイルするために、JRubyコンパイラがJRubyクラスとResque JRubyクラスの両方にアクセスできるようにするには、何をする必要がありますか?