Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot use 3rd party library which requires Guava 31.1 version due to incompatibility with Corda's Guava 28.0 #7493

@adamturski

Description

@adamturski

I want to add integration with Google PubSub 1.124.2 in Corda 4

compile("com.google.cloud:google-cloud-pubsub:1.124.2")

Simply I have a @CordaService which has a method to publish something to Google PubSub. It builds fine but in runtime I get this error:

Caused by: java.lang.NoSuchMethodError: com.google.common.collect.ImmutableMap$Builder.buildKeepingLast()Lcom/google/common/collect/ImmutableMap;

I found that PubSub library has a dependency
com.google.guava:guava:31.1-jre
where ImmutableMap.buildKeepingLast method was added.

In runtime I checked that ImmutableMap was loaded from here:
(file:/home/xxx/.capsule/apps/net.corda.node.CordaEnterprise_4.6.1/guava-28.0-jre.jar )

Why is that? Why Corda dependency was used instead of workflows dependency?

Code to reproduce:
workflows build gradle

compile("com.google.cloud:google-cloud-pubsub:1.124.2")
compile("com.google.guava:guava:31.1-jre")

Corda Service:

import com.google.api.core.ApiFuture
import com.google.cloud.pubsub.v1.Publisher
import com.google.protobuf.ByteString
import com.google.pubsub.v1.PubsubMessage
import com.google.pubsub.v1.TopicName
import net.corda.core.node.AppServiceHub
import net.corda.core.node.services.CordaService
import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.core.utilities.loggerFor
import java.util.concurrent.TimeUnit

@CordaService
class EventBusPublisher(private val serviceHub: AppServiceHub) : SingletonSerializeAsToken() {

    companion object {
        val logger = loggerFor<EventBusPublisher>()
    }

    fun publish(message: String) {
        logger.info("Publishing message to event bus: $message")

        val topicName = TopicName.of("fragmos", "corda.event.state-change")
        var publisher: Publisher? = null
        try {
            // Create a publisher instance with default settings bound to the topic
            publisher = Publisher.newBuilder(topicName).build()
            val data: ByteString = ByteString.copyFromUtf8(message)
            val pubsubMessage: PubsubMessage = PubsubMessage.newBuilder().setData(data).build()

            // Once published, returns a server-assigned message id (unique within the topic)
            val messageIdFuture: ApiFuture<String> = publisher.publish(pubsubMessage)
            val messageId: String = messageIdFuture.get()
            logger.info("Published message ID: $messageId")
        } finally {
            if (publisher != null) {
                // When finished with the publisher, shutdown to free up resources.
                publisher.shutdown()
                publisher.awaitTermination(1, TimeUnit.MINUTES)
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions