Java Code Examples for org.apache.pulsar.common.api.proto.PulsarApi#CommandProducer

The following examples show how to use org.apache.pulsar.common.api.proto.PulsarApi#CommandProducer . 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: CommandUtilsTests.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testMetadataFromCommandProducer() {
    Map<String, String> metadata = CommandUtils.metadataFromCommand(newCommandProducer(null, null));
    Assert.assertNotNull(metadata);
    Assert.assertTrue(metadata.isEmpty());

    final String key = "key";
    final String value = "value";

    PulsarApi.CommandProducer cmd = newCommandProducer(key, value);
    metadata = CommandUtils.metadataFromCommand(cmd);
    Assert.assertEquals(1, metadata.size());
    final Map.Entry<String, String> entry = metadata.entrySet().iterator().next();
    Assert.assertEquals(key, entry.getKey());
    Assert.assertEquals(value, entry.getValue());
}
 
Example 2
Source File: MockBrokerService.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleProducer(PulsarApi.CommandProducer producer) {
    producerId = producer.getProducerId();
    if (handleProducer != null) {
        handleProducer.apply(ctx, producer);
        return;
    }
    // default
    ctx.writeAndFlush(Commands.newProducerSuccess(producer.getRequestId(), "default-producer", SchemaVersion.Empty));
}
 
Example 3
Source File: CommandUtilsTests.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private PulsarApi.CommandProducer newCommandProducer(String key, String value) {
    PulsarApi.CommandProducer.Builder cmd = PulsarApi.CommandProducer.newBuilder()
            .setProducerId(1)
            .setRequestId(1)
            .setTopic("my-topic")
            .setProducerName("producer");

    if (key != null && value != null) {
        cmd.addMetadata(PulsarApi.KeyValue.newBuilder().setKey(key).setValue(value).build());
    }

    return cmd.build();
}
 
Example 4
Source File: CommandUtils.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public static Map<String, String> metadataFromCommand(PulsarApi.CommandProducer commandProducer) {
    return toMap(commandProducer.getMetadataList());
}
 
Example 5
Source File: MockBrokerServiceHooks.java    From pulsar with Apache License 2.0 votes vote down vote up
public void apply(ChannelHandlerContext ctx, PulsarApi.CommandProducer producer);