spotify / async-google-pubsub-client

[SUNSET] Async Google Pubsub Client
Apache License 2.0
157 stars 40 forks source link

Error trying to wait for a completable future #24

Closed ciaranarcher closed 6 years ago

ciaranarcher commented 7 years ago

Hi 👋 - thanks for a great project!

We have a use-case where we would like in some situations to wait for the CompletableFuture when publishing, so that we can be sure that pubsub is working as expected.

When we do this we get the following error:

java.util.concurrent.CompletionException: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.google.cloud.pubsub.client.PublishResponse: abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

Here is some sample code to reproduce:

import com.spotify.google.cloud.pubsub.client.Message;
import com.spotify.google.cloud.pubsub.client.Publisher;
import com.spotify.google.cloud.pubsub.client.Pubsub;

import java.util.concurrent.CompletableFuture;

public class PubsubProblem {
    public static void main(String[] args) {
        Publisher publisher = Publisher.builder()
                .pubsub(Pubsub.create())
                .project("test-project")
                .build();

        Message msg = Message.ofEncoded("hello world");

        CompletableFuture<Void> result = publisher.publish("topic", msg)
                .thenAccept(x -> System.out.println(x))
                .exceptionally(t -> {
                    t.printStackTrace();
                    return null;
                });
    }
}

Is there a way around this? We could be missing something obvious. We are using pubsub version 1.27.

Thanks in advance!

Full stack trace:

java.util.concurrent.CompletionException: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.google.cloud.pubsub.client.PublishResponse: abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: [B@6a7df875; line: 1, column: 1]
    at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
    at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
    at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:647)
    at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:632)
    at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
    at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
    at com.spotify.google.cloud.pubsub.client.Publisher$TopicQueue.lambda$null$1(Publisher.java:405)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at com.spotify.google.cloud.pubsub.client.Publisher$TopicQueue.lambda$sendBatch$3(Publisher.java:405)
    at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
    at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
    at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
    at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
    at com.spotify.google.cloud.pubsub.client.PubsubFuture.fail(PubsubFuture.java:291)
    at com.spotify.google.cloud.pubsub.client.PubsubFuture.lambda$wrap$0(PubsubFuture.java:278)
    at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
    at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
    at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
    at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
    at com.spotify.google.cloud.pubsub.client.PubsubFuture.fail(PubsubFuture.java:291)
    at com.spotify.google.cloud.pubsub.client.Pubsub$1.onCompleted(Pubsub.java:827)
    at com.spotify.google.cloud.pubsub.client.Pubsub$1.onCompleted(Pubsub.java:776)
    at com.ning.http.client.providers.netty.future.NettyResponseFuture.getContent(NettyResponseFuture.java:177)
    at com.ning.http.client.providers.netty.future.NettyResponseFuture.done(NettyResponseFuture.java:214)
    at com.ning.http.client.providers.netty.handler.HttpProtocol.finishUpdate(HttpProtocol.java:194)
    at com.ning.http.client.providers.netty.handler.HttpProtocol.handleChunk(HttpProtocol.java:451)
    at com.ning.http.client.providers.netty.handler.HttpProtocol.handle(HttpProtocol.java:474)
    at com.ning.http.client.providers.netty.handler.Processor.messageReceived(Processor.java:88)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleUpstream(ChunkedWriteHandler.java:142)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.jboss.netty.handler.codec.http.HttpContentDecoder.messageReceived(HttpContentDecoder.java:132)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
    at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:459)
    at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536)
    at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.handler.codec.http.HttpClientCodec.handleUpstream(HttpClientCodec.java:92)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
    at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
    at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
    at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
    at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.google.cloud.pubsub.client.PublishResponse: abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: [B@6a7df875; line: 1, column: 1]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:261)
    at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1420)
    at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1011)
    at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:149)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2920)
    at com.spotify.google.cloud.pubsub.client.Json.read(Json.java:47)
    at com.spotify.google.cloud.pubsub.client.Pubsub$1.onCompleted(Pubsub.java:825)
    ... 44 more
sderosiaux commented 7 years ago

Hi @ciaranarcher

This is a problem the PR https://github.com/spotify/async-google-pubsub-client/pull/16 fixes.

You can build your own version with the fix and that will work. (bump automatter version and remove the maven enforcer)

danielnorberg commented 6 years ago

Closing as this should be resolved, please reopen if necessary.