org.apache.pulsar.common.naming.TopicDomain Java Examples
The following examples show how to use
org.apache.pulsar.common.naming.TopicDomain.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TopicsServiceImpl.java From pulsar-manager with Apache License 2.0 | 6 votes |
private List<Map<String, String>> getTopicsList( String tenant, String namespace, String requestHost) { List<Map<String, String>> result = new ArrayList<>(); Map<String, List<String>> allTopics = this.getTopicListByPulsarAdmin(tenant, namespace, requestHost); Map<String, List<String>> allPartitionedTopics = this.getPartitionedTopicListByPulsarAdmin(tenant, namespace, requestHost); result.addAll(this.convertTopicList( allTopics.get(TopicDomain.persistent.toString()), allPartitionedTopics.get(TopicDomain.persistent.toString()), TopicDomain.persistent.toString(), requestHost )); result.addAll(this.convertTopicList( allTopics.get(TopicDomain.non_persistent.toString()), allPartitionedTopics.get(TopicDomain.non_persistent.toString()), TopicDomain.non_persistent.toString(), requestHost )); return result; }
Example #2
Source File: TopicsServiceImpl.java From pulsar-manager with Apache License 2.0 | 6 votes |
private Map<String, List<String>> parseTopics(List<String> topics) { Map<String, List<String>> result = new HashMap<>(); List<String> persistentTopics = new ArrayList<>(); List<String> nonPersistentTopics = new ArrayList<>(); for (String topic : topics) { TopicName topicName = TopicName.get(topic); if (TopicDomain.persistent.equals(topicName.getDomain())) { persistentTopics.add(topic); } else { nonPersistentTopics.add(topic); } } result.put(TopicDomain.persistent.toString(), persistentTopics); result.put(TopicDomain.non_persistent.toString(), nonPersistentTopics); return result; }
Example #3
Source File: HttpTopicLookupv2Test.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void crossColoLookup() throws Exception { TopicLookup destLookup = spy(new TopicLookup()); doReturn(false).when(destLookup).isRequestHttps(); destLookup.setPulsar(pulsar); doReturn("null").when(destLookup).clientAppId(); Field uriField = PulsarWebResource.class.getDeclaredField("uri"); uriField.setAccessible(true); UriInfo uriInfo = mock(UriInfo.class); uriField.set(destLookup, uriInfo); URI uri = URI.create("http://localhost:8080/lookup/v2/destination/topic/myprop/usc/ns2/topic1"); doReturn(uri).when(uriInfo).getRequestUri(); doReturn(true).when(config).isAuthorizationEnabled(); AsyncResponse asyncResponse = mock(AsyncResponse.class); destLookup.lookupTopicAsync(TopicDomain.persistent.value(), "myprop", "usc", "ns2", "topic1", false, asyncResponse); ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class); verify(asyncResponse).resume(arg.capture()); assertEquals(arg.getValue().getClass(), WebApplicationException.class); WebApplicationException wae = (WebApplicationException) arg.getValue(); assertEquals(wae.getResponse().getStatus(), Status.TEMPORARY_REDIRECT.getStatusCode()); }
Example #4
Source File: PersistentTopicsTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testRevokePartitionedTopic() { final String partitionedTopicName = "partitioned-topic"; final int numPartitions = 5; AsyncResponse response = mock(AsyncResponse.class); ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class); persistentTopics.createPartitionedTopic(response, testTenant, testNamespace, partitionedTopicName, numPartitions); verify(response, timeout(5000).times(1)).resume(responseCaptor.capture()); Assert.assertEquals(responseCaptor.getValue().getStatus(), Response.Status.NO_CONTENT.getStatusCode()); String role = "role"; Set<AuthAction> expectActions = new HashSet<>(); expectActions.add(AuthAction.produce); persistentTopics.grantPermissionsOnTopic(testTenant, testNamespace, partitionedTopicName, role, expectActions); persistentTopics.revokePermissionsOnTopic(testTenant, testNamespace, partitionedTopicName, role); Map<String, Set<AuthAction>> permissions = persistentTopics.getPermissionsOnTopic(testTenant, testNamespace, partitionedTopicName); Assert.assertEquals(permissions.get(role), null); TopicName topicName = TopicName.get(TopicDomain.persistent.value(), testTenant, testNamespace, partitionedTopicName); for (int i = 0; i < numPartitions; i++) { TopicName partition = topicName.getPartition(i); Map<String, Set<AuthAction>> partitionPermissions = persistentTopics.getPermissionsOnTopic(testTenant, testNamespace, partition.getEncodedLocalName()); Assert.assertEquals(partitionPermissions.get(role), null); } }
Example #5
Source File: PersistentTopicsTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testGrantPartitionedTopic() { final String partitionedTopicName = "partitioned-topic"; final int numPartitions = 5; AsyncResponse response = mock(AsyncResponse.class); ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class); persistentTopics.createPartitionedTopic(response, testTenant, testNamespace, partitionedTopicName, numPartitions); verify(response, timeout(5000).times(1)).resume(responseCaptor.capture()); Assert.assertEquals(responseCaptor.getValue().getStatus(), Response.Status.NO_CONTENT.getStatusCode()); String role = "role"; Set<AuthAction> expectActions = new HashSet<>(); expectActions.add(AuthAction.produce); persistentTopics.grantPermissionsOnTopic(testTenant, testNamespace, partitionedTopicName, role, expectActions); Map<String, Set<AuthAction>> permissions = persistentTopics.getPermissionsOnTopic(testTenant, testNamespace, partitionedTopicName); Assert.assertEquals(permissions.get(role), expectActions); TopicName topicName = TopicName.get(TopicDomain.persistent.value(), testTenant, testNamespace, partitionedTopicName); for (int i = 0; i < numPartitions; i++) { TopicName partition = topicName.getPartition(i); Map<String, Set<AuthAction>> partitionPermissions = persistentTopics.getPermissionsOnTopic(testTenant, testNamespace, partition.getEncodedLocalName()); Assert.assertEquals(partitionPermissions.get(role), expectActions); } }
Example #6
Source File: PersistentTopicsTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testGetPartitionedTopicsList() throws KeeperException, InterruptedException, PulsarAdminException { AsyncResponse response = mock(AsyncResponse.class); ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class); persistentTopics.createPartitionedTopic(response, testTenant, testNamespace, "test-topic1", 3); verify(response, timeout(5000).times(1)).resume(responseCaptor.capture()); Assert.assertEquals(responseCaptor.getValue().getStatus(), Response.Status.NO_CONTENT.getStatusCode()); response = mock(AsyncResponse.class); responseCaptor = ArgumentCaptor.forClass(Response.class); nonPersistentTopic.createPartitionedTopic(response, testTenant, testNamespace, "test-topic2", 3); verify(response, timeout(5000).times(1)).resume(responseCaptor.capture()); Assert.assertEquals(responseCaptor.getValue().getStatus(), Response.Status.NO_CONTENT.getStatusCode()); List<String> persistentPartitionedTopics = persistentTopics.getPartitionedTopicList(testTenant, testNamespace); Assert.assertEquals(persistentPartitionedTopics.size(), 1); Assert.assertEquals(TopicName.get(persistentPartitionedTopics.get(0)).getDomain().value(), TopicDomain.persistent.value()); List<String> nonPersistentPartitionedTopics = nonPersistentTopic.getPartitionedTopicList(testTenant, testNamespace); Assert.assertEquals(nonPersistentPartitionedTopics.size(), 1); Assert.assertEquals(TopicName.get(nonPersistentPartitionedTopics.get(0)).getDomain().value(), TopicDomain.non_persistent.value()); }
Example #7
Source File: PartitionCreationTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test(dataProvider = "topicDomainProvider") public void testCreateConsumerForNonPartitionedTopicWhenDisableTopicAutoCreation(TopicDomain domain) throws PulsarClientException { conf.setAllowAutoTopicCreation(false); final String topic = domain.value() + "://public/default/testCreateConsumerForNonPartitionedTopicWhenDisableTopicAutoCreation"; try { Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("sub-1").subscribe(); if (domain == TopicDomain.persistent) { Assert.fail("should be failed"); } else { // passed non persistent topic here since we can not avoid auto creation on non persistent topic now. Assert.assertNotNull(consumer); } } catch (PulsarClientException.TopicDoesNotExistException e) { //ok } }
Example #8
Source File: ProducerCreationTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test(dataProvider = "topicDomainProvider") public void testExactlyOnceWithProducerNameSpecified(TopicDomain domain) throws PulsarClientException { Producer<byte[]> producer1 = pulsarClient.newProducer() .topic(TopicName.get(domain.value(), "public", "default", "testExactlyOnceWithProducerNameSpecified").toString()) .producerName("p-name-1") .create(); Assert.assertNotNull(producer1); Producer<byte[]> producer2 = pulsarClient.newProducer() .topic("testExactlyOnceWithProducerNameSpecified") .producerName("p-name-2") .create(); Assert.assertNotNull(producer2); try { pulsarClient.newProducer() .topic("testExactlyOnceWithProducerNameSpecified") .producerName("p-name-2") .create(); Assert.fail("should be failed"); } catch (PulsarClientException.ProducerBusyException e) { //ok here } }
Example #9
Source File: TopicNameUtils.java From kop with Apache License 2.0 | 5 votes |
public static TopicName pulsarTopicName(String topic, int partitionIndex, NamespaceName namespace) { if (topic.startsWith(TopicDomain.persistent.value())) { topic = topic.replace(TopicDomain.persistent.value() + "://", ""); } if (topic.contains(namespace.getNamespaceObject().toString())) { topic = topic.replace(namespace.getNamespaceObject().toString() + "/", ""); } return TopicName.get(TopicDomain.persistent.value(), namespace, topic + PARTITIONED_TOPIC_SUFFIX + partitionIndex); }
Example #10
Source File: CliCommand.java From pulsar with Apache License 2.0 | 5 votes |
static String validateNonPersistentTopic(List<String> params) { String topic = checkArgument(params); TopicName topicName = TopicName.get(topic); if (topicName.getDomain() != TopicDomain.non_persistent) { throw new ParameterException("Need to provide a non-persistent topic name"); } return topicName.toString(); }
Example #11
Source File: CliCommand.java From pulsar with Apache License 2.0 | 5 votes |
static String validatePersistentTopic(List<String> params) { String topic = checkArgument(params); TopicName topicName = TopicName.get(topic); if (topicName.getDomain() != TopicDomain.persistent) { throw new ParameterException("Need to provide a persistent topic name"); } return topicName.toString(); }
Example #12
Source File: SchemaCompatibilityCheckTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(dataProvider = "CanReadLastSchemaCompatibilityStrategy") public void testConsumerWithNotCompatibilitySchema(SchemaCompatibilityStrategy schemaCompatibilityStrategy) throws Exception { final String tenant = PUBLIC_TENANT; final String topic = "test-consumer-compatibility"; String namespace = "test-namespace-" + randomName(16); String fqtn = TopicName.get( TopicDomain.persistent.value(), tenant, namespace, topic ).toString(); NamespaceName namespaceName = NamespaceName.get(tenant, namespace); admin.namespaces().createNamespace( tenant + "/" + namespace, Sets.newHashSet(CLUSTER_NAME) ); admin.namespaces().setSchemaCompatibilityStrategy(namespaceName.toString(), schemaCompatibilityStrategy); admin.schemas().createSchema(fqtn, Schema.AVRO(Schemas.PersonOne.class).getSchemaInfo()); admin.schemas().createSchema(fqtn, Schema.AVRO(SchemaDefinition.builder() .withAlwaysAllowNull(false).withPojo(Schemas.PersonTwo.class).build()).getSchemaInfo()); try { pulsarClient.newConsumer(Schema.AVRO( SchemaDefinition.<Schemas.PersonFour>builder().withAlwaysAllowNull (false).withSupportSchemaVersioning(true). withPojo(Schemas.PersonFour.class).build())) .subscriptionName("test") .topic(fqtn) .subscribe(); } catch (Exception e) { Assert.assertTrue(e.getMessage().contains("Unable to read schema")); } }
Example #13
Source File: SchemaCompatibilityCheckTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(dataProvider = "ReadAllCheckSchemaCompatibilityStrategy") public void testConsumerCompatibilityReadAllCheckTest(SchemaCompatibilityStrategy schemaCompatibilityStrategy) throws Exception { final String tenant = PUBLIC_TENANT; final String topic = "test-consumer-compatibility"; String namespace = "test-namespace-" + randomName(16); String fqtn = TopicName.get( TopicDomain.persistent.value(), tenant, namespace, topic ).toString(); NamespaceName namespaceName = NamespaceName.get(tenant, namespace); admin.namespaces().createNamespace( tenant + "/" + namespace, Sets.newHashSet(CLUSTER_NAME) ); admin.namespaces().setSchemaCompatibilityStrategy(namespaceName.toString(), schemaCompatibilityStrategy); admin.schemas().createSchema(fqtn, Schema.AVRO(Schemas.PersonOne.class).getSchemaInfo()); admin.schemas().createSchema(fqtn, Schema.AVRO(SchemaDefinition.builder() .withAlwaysAllowNull(false).withPojo(Schemas.PersonTwo.class).build()).getSchemaInfo()); try { pulsarClient.newConsumer(Schema.AVRO( SchemaDefinition.<Schemas.PersonThree>builder().withAlwaysAllowNull (false).withSupportSchemaVersioning(true). withPojo(Schemas.PersonThree.class).build())) .subscriptionName("test") .topic(fqtn) .subscribe(); } catch (Exception e) { Assert.assertTrue(e.getMessage().contains("Unable to read schema")); } }
Example #14
Source File: HttpTopicLookupv2Test.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testNotEnoughLookupPermits() throws Exception { BrokerService brokerService = pulsar.getBrokerService(); doReturn(new Semaphore(0)).when(brokerService).getLookupRequestSemaphore(); TopicLookup destLookup = spy(new TopicLookup()); doReturn(false).when(destLookup).isRequestHttps(); destLookup.setPulsar(pulsar); doReturn("null").when(destLookup).clientAppId(); Field uriField = PulsarWebResource.class.getDeclaredField("uri"); uriField.setAccessible(true); UriInfo uriInfo = mock(UriInfo.class); uriField.set(destLookup, uriInfo); URI uri = URI.create("http://localhost:8080/lookup/v2/destination/topic/myprop/usc/ns2/topic1"); doReturn(uri).when(uriInfo).getRequestUri(); doReturn(true).when(config).isAuthorizationEnabled(); AsyncResponse asyncResponse1 = mock(AsyncResponse.class); destLookup.lookupTopicAsync(TopicDomain.persistent.value(), "myprop", "usc", "ns2", "topic1", false, asyncResponse1); ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class); verify(asyncResponse1).resume(arg.capture()); assertEquals(arg.getValue().getClass(), WebApplicationException.class); WebApplicationException wae = (WebApplicationException) arg.getValue(); assertEquals(wae.getResponse().getStatus(), Status.SERVICE_UNAVAILABLE.getStatusCode()); }
Example #15
Source File: PersistentTopicsTest.java From pulsar with Apache License 2.0 | 5 votes |
@Override @BeforeMethod protected void setup() throws Exception { super.internalSetup(); persistentTopics = spy(new PersistentTopics()); persistentTopics.setServletContext(new MockServletContext()); persistentTopics.setPulsar(pulsar); doReturn(mockZooKeeper).when(persistentTopics).globalZk(); doReturn(mockZooKeeper).when(persistentTopics).localZk(); doReturn(pulsar.getConfigurationCache().propertiesCache()).when(persistentTopics).tenantsCache(); doReturn(pulsar.getConfigurationCache().policiesCache()).when(persistentTopics).policiesCache(); doReturn(false).when(persistentTopics).isRequestHttps(); doReturn(null).when(persistentTopics).originalPrincipal(); doReturn("test").when(persistentTopics).clientAppId(); doReturn(TopicDomain.persistent.value()).when(persistentTopics).domain(); doNothing().when(persistentTopics).validateAdminAccessForTenant(this.testTenant); doReturn(mock(AuthenticationDataHttps.class)).when(persistentTopics).clientAuthData(); nonPersistentTopic = spy(new NonPersistentTopics()); nonPersistentTopic.setServletContext(new MockServletContext()); nonPersistentTopic.setPulsar(pulsar); doReturn(mockZooKeeper).when(nonPersistentTopic).globalZk(); doReturn(mockZooKeeper).when(nonPersistentTopic).localZk(); doReturn(pulsar.getConfigurationCache().propertiesCache()).when(nonPersistentTopic).tenantsCache(); doReturn(pulsar.getConfigurationCache().policiesCache()).when(nonPersistentTopic).policiesCache(); doReturn(false).when(nonPersistentTopic).isRequestHttps(); doReturn(null).when(nonPersistentTopic).originalPrincipal(); doReturn("test").when(nonPersistentTopic).clientAppId(); doReturn(TopicDomain.non_persistent.value()).when(nonPersistentTopic).domain(); doNothing().when(nonPersistentTopic).validateAdminAccessForTenant(this.testTenant); doReturn(mock(AuthenticationDataHttps.class)).when(nonPersistentTopic).clientAuthData(); admin.clusters().createCluster("use", new ClusterData("http://broker-use.com:8080")); admin.clusters().createCluster("test", new ClusterData("http://broker-use.com:8080")); admin.tenants().createTenant(this.testTenant, new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet(testLocalCluster, "test"))); admin.namespaces().createNamespace(testTenant + "/" + testNamespace, Sets.newHashSet(testLocalCluster, "test")); }
Example #16
Source File: ProducerCreationTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(dataProvider = "topicDomainProvider") public void testGeneratedNameProducerReconnect(TopicDomain domain) throws PulsarClientException, InterruptedException { ProducerImpl<byte[]> producer = (ProducerImpl<byte[]>) pulsarClient.newProducer() .topic(TopicName.get(domain.value(), "public", "default", "testGeneratedNameProducerReconnect").toString()) .create(); Assert.assertTrue(producer.isConnected()); //simulate create producer timeout. Thread.sleep(3000); producer.getConnectionHandler().connectionClosed(producer.getConnectionHandler().cnx()); Assert.assertFalse(producer.isConnected()); Thread.sleep(3000); Assert.assertEquals(producer.getConnectionHandler().getEpoch(), 1); Assert.assertTrue(producer.isConnected()); }
Example #17
Source File: PartitionCreationTest.java From pulsar with Apache License 2.0 | 5 votes |
@DataProvider(name = "topicDomainProvider") public Object[][] topicDomainProvider() { return new Object[][] { { TopicDomain.persistent }, { TopicDomain.non_persistent } }; }
Example #18
Source File: TopicsServiceImpl.java From pulsar-manager with Apache License 2.0 | 5 votes |
private List<Map<String, Object>> getTopicStats( String env, String tenant, String namespace, String requestHost) { List<Map<String, Object>> result = new ArrayList<>(); Map<String, List<String>> allTopics = this.getTopicListByPulsarAdmin(tenant, namespace, requestHost); Map<String, List<String>> allPartitionedTopics = this.getPartitionedTopicListByPulsarAdmin(tenant, namespace, requestHost); result.addAll(this.getTopicsStatsList( env, tenant, namespace, TopicDomain.persistent.toString(), this.convertTopicList( allTopics.get(TopicDomain.persistent.toString()), allPartitionedTopics.get(TopicDomain.persistent.toString()), TopicDomain.persistent.toString(), requestHost ) )); result.addAll(this.getTopicsStatsList( env, tenant, namespace, TopicDomain.non_persistent.toString(), this.convertTopicList( allTopics.get(TopicDomain.non_persistent.toString()), allPartitionedTopics.get(TopicDomain.non_persistent.toString()), TopicDomain.non_persistent.toString(), requestHost ) )); return result; }
Example #19
Source File: ProducerCreationTest.java From pulsar with Apache License 2.0 | 5 votes |
@DataProvider(name = "topicDomainProvider") public Object[][] topicDomainProvider() { return new Object[][] { { TopicDomain.persistent }, { TopicDomain.non_persistent } }; }
Example #20
Source File: NamespaceService.java From pulsar with Apache License 2.0 | 5 votes |
public CompletableFuture<List<String>> getPartitions(NamespaceName namespaceName, TopicDomain topicDomain) { String path = PulsarWebResource.path(PARTITIONED_TOPIC_PATH_ZNODE, namespaceName.toString(), topicDomain.toString()); if (LOG.isDebugEnabled()) { LOG.debug("Getting children from partitioned-topics now: {}", path); } return pulsar.getLocalZkCache().getChildrenAsync(path, null).thenCompose(topics -> { CompletableFuture<List<String>> result = new CompletableFuture<>(); List<String> resultPartitions = Collections.synchronizedList(Lists.newArrayList()); if (CollectionUtils.isNotEmpty(topics)) { List<CompletableFuture<List<String>>> futures = Lists.newArrayList(); for (String topic : topics) { String partitionedTopicName = String.format("%s://%s/%s", topicDomain.value(), namespaceName.toString(), decode(topic)); CompletableFuture<List<String>> future = getPartitionsForTopic(TopicName.get(partitionedTopicName)); futures.add(future); future.thenAccept(resultPartitions::addAll); } FutureUtil.waitForAll(futures).whenComplete((v, ex) -> { if (ex != null) { result.completeExceptionally(ex); } else { result.complete(resultPartitions); } }); } else { result.complete(resultPartitions); } return result; }); }
Example #21
Source File: PartitionCreationTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(dataProvider = "topicDomainProvider") public void testCreateConsumerForPartitionedTopicWhenDisableTopicAutoCreation(TopicDomain domain) throws PulsarAdminException, PulsarClientException { conf.setAllowAutoTopicCreation(false); final String topic = domain.value() + "://public/default/testCreateConsumerWhenDisableTopicAutoCreation"; admin.topics().createPartitionedTopic(topic, 3); Assert.assertNotNull(pulsarClient.newConsumer().topic(topic).subscriptionName("sub-1").subscribe()); }
Example #22
Source File: PartitionCreationTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(dataProvider = "topicDomainProvider") public void testCreateConsumerForPartitionedTopicWhenEnableTopicAutoCreation(TopicDomain domain) throws PulsarAdminException, PulsarClientException { conf.setAllowAutoTopicCreation(true); final String topic = domain.value() + "://public/default/testCreateConsumerForPartitionedTopicWhenEnableTopicAutoCreation"; admin.topics().createPartitionedTopic(topic, 3); Assert.assertNotNull(pulsarClient.newConsumer().topic(topic).subscriptionName("sub-1").subscribe()); }
Example #23
Source File: SchemaTest.java From pulsar with Apache License 2.0 | 4 votes |
@Test public void testCreateSchemaAfterDeletion() throws Exception { final String tenant = PUBLIC_TENANT; final String namespace = "test-namespace-" + randomName(16); final String topic = "test-create-schema-after-deletion"; final String fqtn = TopicName.get( TopicDomain.persistent.value(), tenant, namespace, topic ).toString(); admin.namespaces().createNamespace( tenant + "/" + namespace, Sets.newHashSet(pulsarCluster.getClusterName()) ); // Create a topic with `Person` try (Producer<Person> producer = client.newProducer(Schema.AVRO(Person.class)) .topic(fqtn) .create() ) { Person person = new Person(); person.setName("Tom Hanks"); person.setAge(60); producer.send(person); log.info("Successfully published person : {}", person); } log.info("Deleting schema of topic {}", fqtn); // delete the schema admin.schemas().deleteSchema(fqtn); log.info("Successfully deleted schema of topic {}", fqtn); // after deleting the topic, try to create a topic with a different schema try (Producer<Student> producer = client.newProducer(Schema.AVRO(Student.class)) .topic(fqtn) .create() ) { Student student = new Student(); student.setName("Tom Jerry"); student.setAge(30); student.setGpa(6); student.setGpa(10); producer.send(student); log.info("Successfully published student : {}", student); } }
Example #24
Source File: SchemaTest.java From pulsar with Apache License 2.0 | 4 votes |
@Test public void testMultiVersionSchema() throws Exception { final String tenant = PUBLIC_TENANT; final String namespace = "test-namespace-" + randomName(16); final String topic = "test-multi-version-schema"; final String fqtn = TopicName.get( TopicDomain.persistent.value(), tenant, namespace, topic ).toString(); admin.namespaces().createNamespace( tenant + "/" + namespace, Sets.newHashSet(pulsarCluster.getClusterName()) ); Producer<Person> producer = client.newProducer(Schema.AVRO( SchemaDefinition.<Person>builder().withAlwaysAllowNull (false).withSupportSchemaVersioning(true). withPojo(Person.class).build())) .topic(fqtn) .create(); Person person = new Person(); person.setName("Tom Hanks"); person.setAge(60); Consumer<PersonConsumeSchema> consumer = client.newConsumer(Schema.AVRO( SchemaDefinition.<PersonConsumeSchema>builder().withAlwaysAllowNull (false).withSupportSchemaVersioning(true). withPojo(PersonConsumeSchema.class).build())) .subscriptionName("test") .topic(fqtn) .subscribe(); producer.send(person); log.info("Successfully published person : {}", person); PersonConsumeSchema personConsumeSchema = consumer.receive().getValue(); assertEquals("Tom Hanks", personConsumeSchema.getName()); assertEquals(60, personConsumeSchema.getAge()); assertEquals("male", personConsumeSchema.getGender()); producer.close(); consumer.close(); log.info("Successfully consumer personConsumeSchema : {}", personConsumeSchema); }
Example #25
Source File: TopicLookupBase.java From pulsar with Apache License 2.0 | 4 votes |
protected TopicName getTopicName(String topicDomain, String tenant, String cluster, String namespace, @Encoded String encodedTopic) { String decodedName = Codec.decode(encodedTopic); return TopicName.get(TopicDomain.getEnum(topicDomain).value(), tenant, cluster, namespace, decodedName); }
Example #26
Source File: SchemaTest.java From pulsar with Apache License 2.0 | 4 votes |
@Test public void testAvroLogicalType() throws Exception { final String tenant = PUBLIC_TENANT; final String namespace = "test-namespace-" + randomName(16); final String topic = "test-logical-type-schema"; final String fqtn = TopicName.get( TopicDomain.persistent.value(), tenant, namespace, topic ).toString(); admin.namespaces().createNamespace( tenant + "/" + namespace, Sets.newHashSet(pulsarCluster.getClusterName()) ); AvroLogicalType messageForSend = AvroLogicalType.builder() .decimal(new BigDecimal("12.34")) .timestampMicros(System.currentTimeMillis() * 1000) .timestampMillis(Instant.parse("2019-03-26T04:39:58.469Z")) .timeMillis(LocalTime.now()) .timeMicros(System.currentTimeMillis() * 1000) .date(LocalDate.now()) .build(); Producer<AvroLogicalType> producer = client .newProducer(Schema.AVRO(SchemaDefinition.<AvroLogicalType>builder().withPojo(AvroLogicalType.class) .withJSR310ConversionEnabled(true).build())) .topic(fqtn) .create(); Consumer<AvroLogicalType> consumer = client .newConsumer(Schema.AVRO(AvroLogicalType.class)) .topic(fqtn) .subscriptionName("test") .subscribe(); producer.send(messageForSend); log.info("Successfully published avro logical type message : {}", messageForSend); AvroLogicalType received = consumer.receive().getValue(); assertEquals(received, messageForSend); producer.close(); consumer.close(); log.info("Successfully consumer avro logical type message : {}", received); }
Example #27
Source File: JodaTimeTest.java From pulsar with Apache License 2.0 | 4 votes |
@Test public void testJodaTime() throws PulsarAdminException, PulsarClientException { final String tenant = PUBLIC_TENANT; final String namespace = "test-namespace-" + randomName(16); final String topic = "test-joda-time-schema"; final String fqtn = TopicName.get( TopicDomain.persistent.value(), tenant, namespace, topic ).toString(); admin.namespaces().createNamespace( tenant + "/" + namespace, Sets.newHashSet(pulsarCluster.getClusterName()) ); JodaSchema forSend = new JodaSchema(); forSend.setDecimal(new BigDecimal("12.34")); forSend.setTimeMicros(System.currentTimeMillis() * 1000); forSend.setTimestampMillis(new DateTime("2019-03-26T04:39:58.469Z", ISOChronology.getInstanceUTC())); forSend.setTimeMillis(LocalTime.now()); forSend.setTimeMicros(System.currentTimeMillis() * 1000); forSend.setDate(LocalDate.now()); Producer<JodaSchema> producer = client .newProducer(Schema.AVRO(JodaSchema.class)) .topic(fqtn) .create(); Consumer<JodaSchema> consumer = client .newConsumer(Schema.AVRO(JodaSchema.class)) .topic(fqtn) .subscriptionName("test") .subscribe(); producer.send(forSend); JodaSchema received = consumer.receive().getValue(); assertEquals(received, forSend); producer.close(); consumer.close(); log.info("Successfully Joda time logical type message : {}", received); }
Example #28
Source File: SourceConfigUtils.java From pulsar with Apache License 2.0 | 4 votes |
public static TopicName computeBatchSourceIntermediateTopicName(String tenant, String namespace, String sourceName) { return TopicName.get(TopicDomain.persistent.name(), tenant, namespace, sourceName + "-intermediate"); }
Example #29
Source File: TopicNameUtils.java From kop with Apache License 2.0 | 4 votes |
public static TopicName pulsarTopicName(String topic, NamespaceName namespace) { return TopicName.get(TopicDomain.persistent.value(), namespace, topic); }
Example #30
Source File: PulsarMetadataReader.java From pulsar-flink with Apache License 2.0 | 4 votes |
public static String objectPath2TopicName(ObjectPath objectPath) { NamespaceName ns = NamespaceName.get(objectPath.getDatabaseName()); String topic = objectPath.getObjectName(); TopicName fullName = TopicName.get(TopicDomain.persistent.toString(), ns, topic); return fullName.toString(); }