Search in sources :

Example 1 with MessageMetadata

use of org.apache.pulsar.common.api.proto.MessageMetadata in project flink by apache.

the class PulsarDeserializationSchemaTest method getMessage.

/**
 * Create a test message by given bytes. The message don't contains any meta data.
 */
private <T> Message<byte[]> getMessage(T message, FunctionWithException<T, byte[], Exception> decoder) throws Exception {
    byte[] bytes = decoder.apply(message);
    MessageMetadata metadata = new MessageMetadata();
    ByteBuffer payload = ByteBuffer.wrap(bytes);
    return MessageImpl.create(metadata, payload, Schema.BYTES, "");
}
Also used : MessageMetadata(org.apache.pulsar.common.api.proto.MessageMetadata) ByteBuffer(java.nio.ByteBuffer)

Example 2 with MessageMetadata

use of org.apache.pulsar.common.api.proto.MessageMetadata in project athenz by yahoo.

the class MockAthenzPulsarClient method getPulsarClient.

protected PulsarClientImpl getPulsarClient(String serviceUrl, ClientConfigurationData config) throws PulsarClientException {
    try {
        CompletableFuture asyncProducerResult = null;
        if (serviceUrl == null || serviceUrl.isEmpty()) {
            asyncProducerResult = FutureUtil.failedFuture(new PulsarClientException.InvalidConfigurationException("Producer configuration undefined"));
        }
        PulsarClientImpl pulsarClient = Mockito.mock(PulsarClientImpl.class);
        Producer producer = Mockito.mock(Producer.class);
        Consumer consumer = Mockito.mock(Consumer.class);
        MessageMetadata meta = new MessageMetadata();
        DomainChangeMessage roleChange = new DomainChangeMessage().setDomainName("domain").setObjectType(DomainChangeMessage.ObjectType.ROLE).setApiName("putRole").setObjectName("role1");
        MessageImpl<byte[]> msg = MessageImpl.create(meta, ByteBuffer.wrap(new ObjectMapper().writeValueAsBytes(roleChange)), Schema.BYTES, null);
        Mockito.when(consumer.receive(1, TimeUnit.SECONDS)).thenReturn(msg);
        CompletableFuture finalAsyncProducerResult = asyncProducerResult;
        Mockito.when(pulsarClient.createProducerAsync(any(ProducerConfigurationData.class), any(Schema.class))).thenAnswer(invocation -> {
            if (serviceUrl != null) {
                return ((ProducerConfigurationData) invocation.getArgument(0)).getTopicName() == null ? finalAsyncProducerResult : CompletableFuture.completedFuture(producer);
            }
            return finalAsyncProducerResult;
        });
        Mockito.when(pulsarClient.subscribeAsync(any(ConsumerConfigurationData.class), any(Schema.class), any())).thenReturn(CompletableFuture.completedFuture(consumer));
        return pulsarClient;
    } catch (Exception e) {
        fail();
    }
    return null;
}
Also used : DomainChangeMessage(com.yahoo.athenz.common.messaging.DomainChangeMessage) Schema(org.apache.pulsar.client.api.Schema) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) CompletableFuture(java.util.concurrent.CompletableFuture) MessageMetadata(org.apache.pulsar.common.api.proto.MessageMetadata) Producer(org.apache.pulsar.client.api.Producer) Consumer(org.apache.pulsar.client.api.Consumer) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

MessageMetadata (org.apache.pulsar.common.api.proto.MessageMetadata)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DomainChangeMessage (com.yahoo.athenz.common.messaging.DomainChangeMessage)1 ByteBuffer (java.nio.ByteBuffer)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Consumer (org.apache.pulsar.client.api.Consumer)1 Producer (org.apache.pulsar.client.api.Producer)1 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)1 Schema (org.apache.pulsar.client.api.Schema)1 PulsarClientImpl (org.apache.pulsar.client.impl.PulsarClientImpl)1 ConsumerConfigurationData (org.apache.pulsar.client.impl.conf.ConsumerConfigurationData)1 ProducerConfigurationData (org.apache.pulsar.client.impl.conf.ProducerConfigurationData)1