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

The following examples show how to use org.apache.pulsar.common.api.proto.PulsarApi#CommandSubscribe . 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 testMetadataFromCommandSubscribe() {
    Map<String, String> metadata = CommandUtils.metadataFromCommand(newCommandSubscribe(null, null));
    Assert.assertNotNull(metadata);
    Assert.assertTrue(metadata.isEmpty());

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

    PulsarApi.CommandSubscribe cmd = newCommandSubscribe(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 handleSubscribe(PulsarApi.CommandSubscribe subscribe) {
    if (handleSubscribe != null) {
        handleSubscribe.apply(ctx, subscribe);
        return;
    }
    // default
    ctx.writeAndFlush(Commands.newSuccess(subscribe.getRequestId()));
}
 
Example 3
Source File: CommandUtilsTests.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private PulsarApi.CommandSubscribe newCommandSubscribe(String key, String value) {
    PulsarApi.CommandSubscribe.Builder cmd = PulsarApi.CommandSubscribe.newBuilder()
            .setConsumerId(1)
            .setRequestId(1)
            .setTopic("my-topic")
            .setSubscription("my-subscription")
            .setSubType(PulsarApi.CommandSubscribe.SubType.Shared);

    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.CommandSubscribe commandSubscribe) {
    return toMap(commandSubscribe.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.CommandSubscribe subscribe);