Comments (2)
This works fine:
Dir.glob("pulsar-client/*.jar").each { |f| Java.add_to_classpath File.expand_path f }
pulsar = Java.type('org.apache.pulsar.client.api.PulsarClient')
p pulsar
client = pulsar.builder.serviceUrl("pulsar://localhost:6650/").build
p client
Schema = Java.type('org.apache.pulsar.client.api.Schema')
producer = client.newProducer(Schema.STRING).topic("my-topic").create
p producer
producer[:send].call("My message")
# Or:
Truffle::Interop.invoke_member(producer, :send, "My message")
I followed https://pulsar.apache.org/docs/next/getting-started-standalone/ (including running bin/pulsar standalone
)
and https://pulsar.apache.org/docs/next/client-libraries-java-setup/
and downloaded all Maven jars to a folder with https://stackoverflow.com/a/75183691/388803
So it's producer[:send].call("My message")
not producer['send'].call(-> {"My message"})
which would pass a Proc and not a String.
The Schema.STRING
is also needed otherwise the API seems to expect [B
, i.e. byte[]
.
There is also Truffle::Interop.invoke_member(producer, :send, "My message")
which uses interop explicitly.
from truffleruby.
This seems to be done as follows
producer['send'].call(-> {"My message"})
but I seem to be having trouble typing.
producer['send'].call(-> {"My message"})
#<Polyglot::ForeignException[Java] java.lang.ClassCastException:0x71cdc44c: class com.oracle.truffle.polyglot.PolyglotMapAndFunction cannot be cast to class java.lang.String (com.oracle.truffle.polyglot.PolyglotMapAndFunction is in module org.graalvm.truffle of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')>
backtraces are hidden because TruffleRuby doesn't have a case for the org.truffleruby.language.objects.IsCopyableObjectNodeGen node with values of type com.oracle.truffle.host.HostException
from org.truffleruby.language.objects.IsCopyableObjectNodeGen.executeAndSpecialize(IsCopyableObjectNodeGen.java:168)
from org.truffleruby.language.objects.IsCopyableObjectNodeGen.execute(IsCopyableObjectNodeGen.java:113)
from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.executeAndSpecialize(KernelNodesFactory.java:2953)
from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.execute(KernelNodesFactory.java:2935)
from org.truffleruby.language.control.SequenceNode.execute(SequenceNode.java:38)
from org.truffleruby.language.RubyMethodRootNode.execute(RubyMethodRootNode.java:65) was raised when processing them
Even if one tries to use Java types (if I'm doing it right)
irb(main):007> ST = Java.type('java.lang.String')
=> #<Polyglot::ForeignClass[Java] type java.lang.String>
irb(main):009> s = ST.new("Hello, world")
=> "Hello, world"
irb(main):012> producer['send'].call(-> {s})
#<Polyglot::ForeignException[Java] java.lang.ClassCastException:0x68d272c7: class com.oracle.truffle.polyglot.PolyglotMapAndFunction cannot be cast to class java.lang.String (com.oracle.truffle.polyglot.PolyglotMapAndFunction is in module org.graalvm.truffle of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')>
backtraces are hidden because TruffleRuby doesn't have a case for the org.truffleruby.language.objects.IsCopyableObjectNodeGen node with values of type com.oracle.truffle.host.HostException
from org.truffleruby.language.objects.IsCopyableObjectNodeGen.executeAndSpecialize(IsCopyableObjectNodeGen.java:168)
from org.truffleruby.language.objects.IsCopyableObjectNodeGen.execute(IsCopyableObjectNodeGen.java:113)
from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.executeAndSpecialize(KernelNodesFactory.java:2953)
from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.execute(KernelNodesFactory.java:2935)
from org.truffleruby.language.control.SequenceNode.execute(SequenceNode.java:38)
from org.truffleruby.language.RubyMethodRootNode.execute(RubyMethodRootNode.java:65) was raised when processing them
from truffleruby.
Related Issues (20)
- Error installing pg 1.1.4 HOT 1
- concurrent-ruby Fixed Thread Pool memory leak HOT 2
- Array#pack does not support :buffer kwarg HOT 1
- Monkey patching not working HOT 2
- TruffleRuby set `host_cpu` to `aarch64` on `arm64-darwin` causing `REUSE_AS_BINARY_ON_TRUFFLERUBY` to not work as expected HOT 3
- rails 7, rails new - no such filre or directory HOT 1
- gem error: OpenSSL is not available in Oracle Linux 9 HOT 4
- dead handle with mongoid HOT 8
- Benchmark ORM on Truffleruby vs CRuby HOT 1
- using "find pattern" matching in a dynamically-defined method results in NPE HOT 3
- Segfault in 24.1.0-dev GFTC builds with pg driver HOT 6
- `StringIO` does not set the ASCII-8BIT encoding in `wb` mode HOT 1
- Hash.to_h with block not yielding splat args well HOT 2
- Documentation: installing TruffleRuby in JVM mode from RVM HOT 1
- Segfault in 24.2.0-dev GFTC when bundle installing HOT 4
- Java exceptions not caught by bare rescue HOT 8
- EA build: Crashes when `config/puma.rb` starts with the line `#!/usr/bin/env puma` HOT 3
- rb_mutex_synchronize should pass the return value as-is HOT 1
- `rb_str_resize(Qfalse, 0)` with NKF and without C extensions lock HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from truffleruby.