У меня странная проблема. Я создал pubsub topi c и публикую сообщения в topi c. Когда я использую java основной метод, я могу успешно опубликовать sh сообщения, но когда я использую сообщение о вызовах метода diffrent не публикуется. При отладке я вижу, что вызов в коде обоих методов зависает на 100%
List<String> messageIds = ApiFutures.allAsList(futures).get();
Как опубликовать sh сообщение с использованием неосновного метода. Вот мой код ниже.
@Slf4j
public class GCPMessagePublisher {
private static final String PROJECT_ID = "myProjId";
public static void main(String[] args) throws Exception
{
String topicId = "testTopic";
int messageCount = 10;
String message="Hello GCP";
ProjectTopicName topicName = ProjectTopicName.of(PROJECT_ID, topicId);
List<ApiFuture<String>> futures = new ArrayList<>();
Publisher publisher=null;
try {
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream("GCP Credential Here........"));
publisher = Publisher.newBuilder(topicName).setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
// convert message to bytes
ByteString data = ByteString.copyFromUtf8(message);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder()
.setData(data)
.build();
// Schedule a message to be published. Messages are automatically batched.
ApiFuture<String> future = publisher.publish(pubsubMessage);
futures.add(future);
} finally {
// Wait on any pending requests
List<String> messageIds = ApiFutures.allAsList(futures).get();
for (String messageId : messageIds) {
System.out.println("messageId Printing is "+messageId);
}
if (publisher != null) {
// When finished with the partypublisher, shutdown to free up resources.
publisher.shutdown();
}
}
}
public static void putMessageOnGCP(String Message) throws Exception
{
//log.info("The outgoing message to GCP PUBSUB is : "+message);
String topicId = "testTopic";
String message="Hi GCP";
ProjectTopicName topicName = ProjectTopicName.of(PROJECT_ID, topicId);
List<ApiFuture<String>> futures = new ArrayList<>();
Publisher publisher=null;
try {
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream("GCP Credential Here.........."));
publisher = Publisher.newBuilder(topicName).setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
// convert message to bytes
ByteString data = ByteString.copyFromUtf8(message);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder()
.setData(data)
.build();
// Schedule a message to be published. Messages are automatically batched.
ApiFuture<String> future = publisher.publish(pubsubMessage);
futures.add(future);
}catch (Exception e)
{
}
finally {
// Wait on any pending requests
List<String> messageIds = ApiFutures.allAsList(futures).get();
for (String messageId : messageIds) {
System.out.println(messageId);
}
if (publisher != null) {
// When finished with the partypublisher, shutdown to free up resources.
publisher.shutdown();
}
}
}
}
Когда я звоню из другого метода, я получаю следующую ошибку. Когда я проверяю учетные данные Google, я вижу, что он читает контент из учетных данных Google JSON Файл.
Причина: com.google.api.gax.rp c .UnavailableException: io.grp c .StatusRuntimeException: UNAVAILABLE: исключение io Канал канала: [SslHandler # 0, ProtocolNegotiators $ ClientTlsHandler # 0, WriteBufflerA 0 # 0, DefaultChannelPipeline $ TailContext # 0] на com.google.api.gax.rp c .ApiExceptionFactory.createException (ApiExceptionFactory. java: 69) на com.google.api.gax.grp c .GrpcApiExceptionFactory .create (GrpcApiExceptionFactory. java: 72) на com.google.api.gax.grp c .GrpcApiExceptionFactory.create (GrpcApiExceptionFactory. java: 60) на com.google.api.gax.grp c. .GrpcExceptionCallable $ ExceptionTransformingFuture.onFailure (GrpcExceptionCallable. java: 97) на com.google.api.core.ApiFutures $ 1.onFailure (ApiFutures. java: 68) на com.google.common.ut il.concurrent.Futures $ CallbackListener.run (Futures. java: 1039) на com.google.common.util.concurrent.DirectExecutor.execute (DirectExecutor. java: 30) на com.google.common.util. concurrent.AbstractFuture.executeListener (AbstractFuture. java: 1165) на com.google.common.util.concurrent.AbstractFuture.complete (AbstractFuture. java: 958) на com.google.common.util.concurrent.AbstractFuture. setException (AbstractFuture. java: 749) в io.grp c .stub.ClientCalls $ GrpcFuture.setException (ClientCalls. java: 522) в io.grp c .stub.ClientCalls $ UnaryStreamToFuture.onClose ( ClientCalls. java: 497) по адресу io.grp c .internal.ClientCallImpl.closeObserver (ClientCallImpl. java: 426) по адресу io.grp c .internal.ClientCallImpl.access $ 500 (ClientCallImpl. * 1041 : 66) в io.grp c .internal.ClientCallImpl $ ClientStreamListenerImpl.close (ClientCallImpl. java: 689) в io.grp c .internal.ClientCallImpl $ ClientStreamListenerImpl.access $ 900 (ClientCallI 10 :45. 577) по адресу io.grp c .internal.ClientCallImpl $ ClientStr eamListenerImpl $ 1StreamClosed.runInternal (ClientCallImpl. java: 751) по адресу io.grp c .internal.ClientCallImpl $ ClientStreamListenerImpl $ 1StreamClosed.runInContext (ClientCallImpl. java * .inp. 740): 740): 740) ContextRunnable.run (ContextRunnable. java: 37) в io.grp c .internal.SerializingExecutor.run (SerializingExecutor. java: 123) в java .base / java .util.concurrent.Executors $ RunnableAdapter.call (Исполнители. java: 515) на java .base / java .util.concurrent.FutureTask.run $$$ capture (FutureTask. java: 264) на java .base /java.util.concurrent.FutureTask.run(FutureTask.java) в java .base / java .util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run (ScheduledThreadPoolExecutor. java 304): *1065* 304 1066 * .base / java .util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor. java: 1128) в java .base / java .util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor. *: 628) ... еще 1 причина: io.grp c .StatusRuntimeException: НЕДОСТУПНО: io excepti в канальном канале: [SslHandler # 0, ProtocolNegotiators $ ClientTlsHandler # 0, WriteBufferingAndExceptionHandler # 0, DefaultChannelPipeline $ TailContext # 0] в io.grp c .Status.asRuntimeException (Status. java: 533) ... еще 16 Вызывается: javax. net .ssl.SSLHandshakeException: общая проблема OpenSslEngine в io.grp c .netty.shaded.io.netty.handler.ssl.ReferenceCountingOpenSslEngine.handshakeException (ReferenceCountingOpenSsLEngo. At at 8). 1077 .grp c .netty.shaded.io. netty.handler.ssl.ReferenceCountingOpenSslEngine.wrap (ReferenceCountingOpenSslEngine. java: 770) в java .base / javax. net .ssl.SSLEngine.wrap (SSLEngine. java: 519) в io.grp c .netty.shaded.io.netty.handler.ssl.SslHandler.wrap (SslHandler. java: 1043) на io.grp c .netty.shaded.io.netty.handler.ssl.SslHandler.wrapNonAppData (SslHandler. java: 934) по адресу io.grp c .netty.shaded.io.netty.handler.ssl.SslHandler.unwrap (SslHandler. java: 1392) по адресу io.grp c .netty .shaded.io.netty.handler.ssl.SslHandler.decodeJdkCompatible (SslHandler. java: 1224) по адресу io.grp c .netty.shaded.io.netty.handler.ssl.SslHandler.decode (SslHandler. java: 1271) по адресу io.grp c .netty.shaded.io.netty.handler.code c .ByteToMessageDecoder.decodeRemovalReentryProtection (ByteToMessageDecoder. java: 505) по адресу io.grp c .netty. shaded.io.netty.handler.code c .ByteToMessageDecoder.callDecode (ByteToMessageDecoder. java: 444) в io.grp c .netty.shaded.io.netty.handler.code c .ByteToMessageDecoder channelRead (Byte ToMessageDecoder. java: 283) на io.grp c .netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext. java: 374) на io.grp c .net.s io.netty.channel. .grp c .netty.shaded.io.netty.channel.DefaultChannelPipeline $ HeadContext.channelRead (DefaultChannelPipeline. java: 1422) по адресу io.grp c .netty.shaded.io.netty.channel.AbstractChannelHandlerContext. invokeChannelRead (AbstractChannelHandlerContext. java: 374) в io.grp c .netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext. java: 360) в io.gr. shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead (DefaultChannelPipeline. java: 931) по адресу io.grp c .netty.shaded.io.netty.channe l.nio.AbstractNioByteChannel $ NioByteUnsafe.read (AbstractNioByteChannel. java: 163) в io.grp c .netty.shaded.io.netty.channel.nio.NioEventL oop .processSelectedKey (NioE. java: 700) на io.grp c .netty.shaded.io.netty.channel.nio.NioEventL oop .processSelectedKeysOptimized (NioEventL oop. java: 635) на io.grp c .netty.shaded.io.netty.channel.nio.NioEventL oop .processSelectedKeys (NioEventL oop. java: 552) по адресу io.grp c .netty.shaded.io.netty.channel. nio.NioEventL oop .run (NioEventL oop. java: 514) на io.grp c .netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor $ 6.run (SingleThreadEventExecutor. java : 1044) в io.grp c .netty.shaded.io.netty.util.internal.ThreadExecutorMap $ 2.run (ThreadExecutorMap. java: 74) в io.grp c .netty.shaded.io. netty.util.concurrent.FastThreadLocalRunnable.run (FastThreadLocalRunnable. java: 30) ... еще 1 причина: sun.security.validator.ValidatorException: сбой построения пути PKIX: sun.security.provider.certpath .SunCertPathBuilderException: невозможно найти действительный путь сертификации для запрошенной цели в java .base / sun.security.validator.PKIXValidator.doBuild (PKIXValidator. java: 385) в java .base / sun.security.validator. PKIXValidator.engineValidate (PKIXValidator. java: 290) в java .base / sun.security.validator.Validator.validate (Validator. java: 264) в java .base / sun.security.ssl. X509TrustManagerImpl.validate (X509TrustManagerImpl. java: 313) в java .base / sun.security.ssl.X509TrustManagerImpl.checkTrusted (X509TrustManagerImpl. java: 276) .Sase / 1150. X509TrustManagerImpl.checkServerTrusted (X509TrustManagerImpl. java: 141) по адресу io.grp c .netty.shaded.io.netty.handler.ssl.ReferenceCountingOpenSslClientContext $ ExtendedTrustManagerVerrifenConnect.IpenCateCallSec. c .netty.shaded.io.netty. handler.ssl.ReferenceCountingOpenSslContext $ AbstractCertificateVerifier.verify (ReferenceCountingOpenSslContext. java: 699) в io.grp c .netty.shaded.io.netty.internal.tcnative.SSL.readFromSSL (собственный метод) в io 1157 * .netty.shaded.io.netty. (ReferenceCountingOpenSslEngine. java: 1172) по адресу io.grp c .netty.shaded.io.netty.handler.ssl.ReferenceCountingOpenSslEngine.unwrap (ReferenceCountingOpenSslEngine. java: 1289) по адресу io.grp c. .shaded.io.netty.handler.ssl.SslHandler $ SslEngineType $ 1.unwrap (SslHandler. java: 199) в io.grp c .netty.shaded.io.netty.handler.ssl.SslHandler.unwrap ( SslHandler. java: 1329) ... еще 21 Причина: sun.security.provider.certpath.SunCertPathBuilderException: невозможно найти действительный путь сертификации для запрошенной цели в java .base / sun.security.provider.certpath. SunC ertPathBuilder.build (SunCertPathBuilder. java: 141) в java .base / sun.security.provider.certpath.SunCertPathBuilder.engineBuild (SunCertPathBuilder. java: 126) в java .base /. security.cert.CertPathBuilder.build (CertPathBuilder. java: 297) в java .base / sun.security.validator.PKIXValidator.doBuild (PKIXValidator. java: 380) ... еще 34
Нужно ли что-нибудь добавить, чтобы это работало