Вариант 1 - работает
Код: Выделить всё
import com.google.cloud.pubsub.v1.TopicAdminClient;
import com.google.cloud.pubsub.v1.TopicAdminSettings;
import com.google.pubsub.v1.ProjectName;
import com.google.pubsub.v1.Topic;
import java.io.IOException;
import java.util.stream.StreamSupport;
public class App {
public static void main(String[] args) throws IOException {
TopicAdminSettings topicAdminSettings = TopicAdminSettings.newBuilder().build();
TopicAdminClient topicClient = TopicAdminClient.create(topicAdminSettings);
TopicAdminClient.ListTopicsPagedResponse listTopicsPagedResponse = topicClient.listTopics(ProjectName.newBuilder().setProject("my-project-id").build());
StreamSupport.stream(listTopicsPagedResponse.iterateAll().spliterator(), false)
.map(Topic::getName)
.forEach(System.out::println);
topicClient.close();
}
}
Код: Выделить всё
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.cloud.pubsub.v1.TopicAdminClient;
import com.google.cloud.pubsub.v1.TopicAdminSettings;
import com.google.pubsub.v1.ProjectName;
import com.google.pubsub.v1.Topic;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import java.io.IOException;
import java.util.stream.StreamSupport;
public class App {
public static void main(String[] args) throws IOException {
ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:8086").usePlaintext().build();
TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
TopicAdminSettings topicAdminSettings = TopicAdminSettings.newBuilder()
.setTransportChannelProvider(channelProvider)
.build();
TopicAdminClient topicClient = TopicAdminClient.create(topicAdminSettings);
TopicAdminClient.ListTopicsPagedResponse listTopicsPagedResponse = topicClient.listTopics(ProjectName.newBuilder().setProject("my-project-id").build());
StreamSupport.stream(listTopicsPagedResponse.iterateAll().spliterator(), false)
.map(Topic::getName)
.forEach(System.out::println);
topicClient.close();
}
}
Причина, по которой мне нужен собственный хост и порт, заключается в том, что у меня есть сквозной тест, который я хочу запустить. локально, среда разработки и тестирования. Эти среды имеют разные хосты.
Подробнее здесь: https://stackoverflow.com/questions/787 ... -with-mana
Мобильная версия