AppEngine标准Java8中的Google PubSub错误:java.lang.NoSuchFieldError:CONTEXT_SPAN_KEY

时间:2018-10-12 08:14:11

标签: java google-app-engine publish-subscribe grpc

我有一个在AppEngine Standard Java8上运行的webapp。该应用程序需要将消息发布到Google PubSub。每当此行执行时:

user  nginx;
worker_processes  1;

error_log  /dev/stdout debug;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    # We only serve static content, the backend is all REST
    sendfile           on;
    sendfile_max_chunk 1m;

    # Send headers in one packet after the first chunk of data has been read
    tcp_nopush     on;

    # Enable no delay to directly send TCP traffic without queing for small packets
    tcp_nodelay on;

    # Use a sane keepalive timeout to reuse the connection if needed
    keepalive_timeout  65;

    # Use GZIP
    gzip on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_min_length  500;
    gzip_buffers  4 32k;
    gzip_types    text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml image/svg;
    gzip_vary on;

    include /etc/nginx/conf.d/*.conf;
}

它将抛出错误“ java.lang.NoSuchFieldError:CONTEXT_SPAN_KEY”。 io.grpc.internal.CensusTracingModule $ TracingClientInterceptor.interceptCall(CensusTracingModule.java:380)。看起来我使用的是没有CONTEXT_SPAN_KEY的“库”的较新版本或较旧版本。有人知道如何针对这个图书馆吗?

我是Google App Engine(Java8)和PubSub的新手,这是我的第一篇Stackoverflow帖子。

在过去的两天里,我一直在努力寻找导致此错误的根本原因,但到目前为止还没有运气。如果有人可以帮助,将不胜感激!

代码如下:

ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);

这是错误消息:

PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8(payload)).build();

  ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);

  // Add an asynchronous callback to handle success / failure
  ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback<String>() {

    @Override
    public void onFailure(Throwable throwable) {
      throwable.printStackTrace();

      if (throwable instanceof ApiException) {
        ApiException apiException = ((ApiException) throwable);
        // details on the API exception
        System.out.println(apiException.getStatusCode().getCode());
        System.out.println(apiException.isRetryable());
      }
      System.out.println("Error publishing message");
    }

pom.xml

[INFO] GCLOUD: INFO: Dev App Server is now running
[INFO] GCLOUD:  published: 
[INFO] GCLOUD: java.lang.NoSuchFieldError: CONTEXT_SPAN_KEY
[INFO] GCLOUD:  at io.grpc.internal.CensusTracingModule$TracingClientInterceptor.interceptCall(CensusTracingModule.java:380)
[INFO] GCLOUD: Error publishing message
[INFO] GCLOUD:  at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
[INFO] GCLOUD:  at io.grpc.internal.CensusStatsModule$StatsClientInterceptor.interceptCall(CensusStatsModule.java:675)
[INFO] GCLOUD:  at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
[INFO] GCLOUD:  at com.google.api.gax.grpc.GrpcHeaderInterceptor.interceptCall(GrpcHeaderInterceptor.java:81)
[INFO] GCLOUD:  at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
[INFO] GCLOUD:  at com.google.api.gax.grpc.GrpcMetadataHandlerInterceptor.interceptCall(GrpcMetadataHandlerInterceptor.java:55)
[INFO] GCLOUD:  at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
[INFO] GCLOUD:  at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:636)
[INFO] GCLOUD:  at com.google.api.gax.grpc.ChannelPool.newCall(ChannelPool.java:77)
[INFO] GCLOUD:  at com.google.api.gax.grpc.GrpcClientCalls.newCall(GrpcClientCalls.java:75)
[INFO] GCLOUD:  at com.google.api.gax.grpc.GrpcDirectCallable.futureCall(GrpcDirectCallable.java:58)
[INFO] GCLOUD:  at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:62)
[INFO] GCLOUD:  at com.google.api.gax.rpc.AttemptCallable.call(AttemptCallable.java:75)
[INFO] GCLOUD:  at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:63)
[INFO] GCLOUD:  at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:41)
[INFO] GCLOUD:  at com.google.api.gax.rpc.BatchingCallable.futureCall(BatchingCallable.java:79)
[INFO] GCLOUD:  at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
[INFO] GCLOUD:  at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
[INFO] GCLOUD:  at com.google.cloud.pubsub.v1.Publisher.publishOutstandingBatch(Publisher.java:322)
[INFO] GCLOUD:  at com.google.cloud.pubsub.v1.Publisher.publishAllOutstanding(Publisher.java:311)
[INFO] GCLOUD:  at com.google.cloud.pubsub.v1.Publisher$3.run(Publisher.java:285)
[INFO] GCLOUD:  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[INFO] GCLOUD:  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[INFO] GCLOUD:  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
[INFO] GCLOUD:  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
[INFO] GCLOUD:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO] GCLOUD:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO] GCLOUD:  at java.lang.Thread.run(Thread.java:745)
[INFO] GCLOUD: Oct 12, 2018 7:25:22 AM com.google.api.server.spi.handlers.EndpointsMethodHandler$RestHandler handle
[INFO] GCLOUD: WARNING: exception occurred while invoking backend method
[INFO] GCLOUD: java.io.IOException: com.fasterxml.jackson.databind.JsonMappingException: ProjectTopicName.getType() not supported (through reference chain: com.google.cloud.pubsub.v1.Publisher["topicName"]->com.google.pubsub.v1.ProjectTopicName["type"])
[INFO] GCLOUD:  at com.google.api.server.spi.response.ServletResponseResultWriter.writeValueAsString(ServletResponseResultWriter.java:212)
[INFO] GCLOUD:  at com.google.api.server.spi.response.ServletResponseResultWriter.write(ServletResponseResultWriter.java:101)
[INFO] GCLOUD:  at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:352)
[INFO] GCLOUD:  at com.google.api.server.spi.handlers.EndpointsMethodHandler$RestHandler.handle(EndpointsMethodHandler.java:119)
[INFO] GCLOUD:  at com.google.api.server.spi.handlers.EndpointsMethodHandler$RestHandler.handle(EndpointsMethodHandler.java:102)
[INFO] GCLOUD:  at com.google.api.server.spi.dispatcher.PathDispatcher.dispatch(PathDispatcher.java:50)
[INFO] GCLOUD:  at com.google.api.server.spi.EndpointsServlet.service(EndpointsServlet.java:72)
[INFO] GCLOUD:  at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1655)
[INFO] GCLOUD:  at com.google.api.control.ControlFilter.doFilter(ControlFilter.java:331)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.api.control.ConfigFilter.doFilter(ConfigFilter.java:125)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:134)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.appengine.tools.development.jetty9.StaticFileFilter.doFilter(StaticFileFilter.java:123)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
[INFO] GCLOUD:  at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
[INFO] GCLOUD:  at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
[INFO] GCLOUD:  at com.google.appengine.tools.development.DevAppServerRequestLogFilter.doFilter(DevAppServerRequestLogFilter.java:44)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
[INFO] GCLOUD:  at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
[INFO] GCLOUD:  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
[INFO] GCLOUD:  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
[INFO] GCLOUD:  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219)
[INFO] GCLOUD:  at com.google.appengine.tools.development.jetty9.DevAppEngineWebAppContext.doScope(DevAppEngineWebAppContext.java:94)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
[INFO] GCLOUD:  at com.google.appengine.tools.development.jetty9.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:595)
[INFO] GCLOUD:  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
[INFO] GCLOUD:  at org.eclipse.jetty.server.Server.handle(Server.java:531)
[INFO] GCLOUD:  at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
[INFO] GCLOUD:  at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
[INFO] GCLOUD:  at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
[INFO] GCLOUD:  at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
[INFO] GCLOUD:  at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
[INFO] GCLOUD:  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)
[INFO] GCLOUD:  at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)
[INFO] GCLOUD:  at java.lang.Thread.run(Thread.java:745)
[INFO] GCLOUD: Caused by: com.fasterxml.jackson.databind.JsonMappingException: ProjectTopicName.getType() not supported (through reference chain: com.google.cloud.pubsub.v1.Publisher["topicName"]->com.google.pubsub.v1.ProjectTopicName["type"])
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:391)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:351)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:727)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1396)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1120)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:993)
[INFO] GCLOUD:  at com.google.api.server.spi.response.ServletResponseResultWriter.writeValueAsString(ServletResponseResultWriter.java:210)
[INFO] GCLOUD:  ... 56 more
[INFO] GCLOUD: Caused by: java.lang.UnsupportedOperationException: ProjectTopicName.getType() not supported
[INFO] GCLOUD:  at com.google.pubsub.v1.ProjectTopicName.getType(ProjectTopicName.java:130)
[INFO] GCLOUD:  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] GCLOUD:  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] GCLOUD:  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] GCLOUD:  at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687)
[INFO] GCLOUD:  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
[INFO] GCLOUD:  ... 66 more
[INFO] GCLOUD: 

2 个答案:

答案 0 :(得分:1)

按lib过滤lib之后,我能够找到原因。我从pom.xml中删除了endpoints-management-control-appengine-all,PubSub开始工作(从本地)。

<dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-management-control-appengine-all</artifactId>
    <version>${endpoints.management.version}</version>
</dependency>

谢谢大家!

答案 1 :(得分:0)

在appengine标准(具有云端点)上使用pubsub 1.52.0(取决于opencensus 0.12.3)进行发布时,我遇到了类似的错误,并通过将opencensus-api(0.18.0)设置为单独的依赖项并排除了该错误,从而解决了该错误来自google-cloud-pubsub依赖项。

    <!-- https://mvnrepository.com/artifact/io.opencensus/opencensus-api -->
<dependency>
    <groupId>io.opencensus</groupId>
    <artifactId>opencensus-api</artifactId>
    <version>0.18.0</version>
</dependency>    

<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub -->
                <dependency>
                    <groupId>com.google.cloud</groupId>
                    <artifactId>google-cloud-pubsub</artifactId>
                    <version>1.52.0</version>
                    <exclusions>
                        <exclusion>
                            <groupId>io.opencensus</groupId>
                            <artifactId>opencensus-api</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>