apache / pulsar

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org/
Apache License 2.0
14.23k stars 3.58k forks source link

[Bug] Unable to run locally using IntelliJ + Ventura MacOS #18441

Open Somnium99 opened 1 year ago

Somnium99 commented 1 year ago

Search before asking

Version

OS : 13.0.1 Ventura MacOS Pulsar : 2.10.2 JDK : Eclipse Temurin-17 IntelliJ : 2022.2.1

Minimal reproduce step

build.gradle.kts :

dependencies {
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
    testImplementation("org.jetbrains.kotlin:kotlin-test")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit")

    implementation("io.ktor:ktor-server-netty:2.1.3")

    implementation("org.apache.pulsar:pulsar-client:2.10.2")

also tried :

     runtimeOnly("io.netty:netty-resolver-dns-classes-macos:4.1.85.Final")
     runtimeOnly("io.netty:netty-resolver-dns-classes-macos:4.1.85.Final:osx-x86_64")

Main.kt :

 Pulsar.client().use {
        val producer = Pulsar.producer(it)
        producer.send("message".toByteArray())
 }

Pulsar.kt

object Pulsar {
    private const val EVENTS_TOPIC = "topic"

    internal fun client() = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build()

    internal fun producer(client: PulsarClient): Producer<ByteArray> {
        return client
            .newProducer()
            .topic(EVENTS_TOPIC)
            .create()
    }

What did you expect to see?

Being able to produce message (send messages through a producer)

What did you see instead?

When trying to use a producer to send messages it says :

[pulsar-client-io-1-1] WARN org.apache.pulsar.client.impl.ConnectionPool - Failed to open connection to localhost/<unresolved>:6650 : org.apache.pulsar.shade.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:6650

[pulsar-client-scheduled-5-1] WARN org.apache.pulsar.client.impl.PulsarClientImpl - [topic: persistent://public/default/topic] Could not get connection while getPartitionedTopicMetadata -- Will try again in 100 ms

[pulsar-client-scheduled-5-1] DEBUG org.apache.pulsar.client.impl.ConnectionPool - Connection for localhost/<unresolved>:6650 not found in cache

Also, I don't know if it's related, but I also get the following stacktrace when building a client :

[main] WARN org.apache.pulsar.shade.io.netty.resolver.dns.DnsServerAddressStreamProviders - Can not find org.apache.pulsar.shade.io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider in the classpath, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS.
[main] WARN org.apache.pulsar.common.util.netty.DnsResolverUtil - Cannot get DNS TTL settings from sun.net.InetAddressCachePolicy class
java.lang.IllegalAccessException: class org.apache.pulsar.common.util.netty.DnsResolverUtil cannot access class sun.net.InetAddressCachePolicy (in module java.base) because module java.base does not export sun.net to unnamed module @3aefe5e5
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
    at java.base/java.lang.reflect.Method.invoke(Method.java:560)
    at org.apache.pulsar.common.util.netty.DnsResolverUtil.<clinit>(DnsResolverUtil.java:46)
    at org.apache.pulsar.client.impl.ConnectionPool.createAddressResolver(ConnectionPool.java:121)
    at org.apache.pulsar.client.impl.ConnectionPool.lambda$new$1(ConnectionPool.java:109)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at org.apache.pulsar.client.impl.ConnectionPool.<init>(ConnectionPool.java:109)
    at org.apache.pulsar.client.impl.ConnectionPool.<init>(ConnectionPool.java:78)
    at org.apache.pulsar.client.impl.ConnectionPool.<init>(ConnectionPool.java:73)
    at org.apache.pulsar.client.impl.PulsarClientImpl.<init>(PulsarClientImpl.java:194)
    at org.apache.pulsar.client.impl.PulsarClientImpl.<init>(PulsarClientImpl.java:150)
    at org.apache.pulsar.client.impl.ClientBuilderImpl.build(ClientBuilderImpl.java:67)
    at MainKt.main(Main.kt:72)

Anything else?

No response

Are you willing to submit a PR?

labuladong commented 1 year ago

I think Connection refused: localhost/127.0.0.1:6650 is the root cause.

Have you started the pulsar standalone first?

Somnium99 commented 1 year ago

Yes, so actually I've tried 3 ways of installing and running pulsar, and only one worked.

I. brew - problem exists

> brew install apache-pulsar
> brew services start apache-pulsar
> pulsar standalone

II. download local binary - problem exists

> download and unzip the binary files, and then go to the directory in terminal
> ./bin/pulsar standalone

III. downloading and running via Docker - Works!

docker run -it -p 6650:6650 -p 8080:8080 --mount source=pulsardata,target=/pulsar/data --mount source=pulsarconf,target=/pulsar/conf apachepulsar/pulsar:2.10.2 bin/pulsar standalone
labuladong commented 1 year ago

I guess you are using 2.10.x version of Pulsar on m1 MacBook. In 2.10.x, there will be an issue using the second way, and the newer version will resolve that issue.

Somnium99 commented 1 year ago

No it's actually a quite an old macbook - Macbook Pro 2019 , 2.6 GHz 6-Core Intel Core i7

labuladong commented 1 year ago

OK, maybe you can search your problem in issues. Or just use docker :)

github-actions[bot] commented 1 year ago

The issue had no activity for 30 days, mark with Stale label.

os-architect commented 1 year ago

same problem here. @Somnium99 , have you found a solution for this?

github-actions[bot] commented 1 year ago

The issue had no activity for 30 days, mark with Stale label.