Search in sources :

Example 1 with CommandNotificationSerializer

use of org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer in project incubator-rya by apache.

the class PeriodicNotificationApplicationIT method init.

@Before
public void init() throws Exception {
    final String topic = rule.getKafkaTopicName();
    rule.createTopic(topic);
    // get user specified props and update with the embedded kafka bootstrap servers and rule generated topic
    props = getProps();
    props.setProperty(NOTIFICATION_TOPIC, topic);
    props.setProperty(KAFKA_BOOTSTRAP_SERVERS, bootstrapServers);
    conf = new PeriodicNotificationApplicationConfiguration(props);
    // create Kafka Producer
    kafkaProps = getKafkaProperties(conf);
    producer = new KafkaProducer<>(kafkaProps, new StringSerializer(), new CommandNotificationSerializer());
    // extract kafka specific properties from application config
    app = PeriodicNotificationApplicationFactory.getPeriodicApplication(conf);
    registrar = new KafkaNotificationRegistrationClient(conf.getNotificationTopic(), producer);
}
Also used : StringSerializer(org.apache.kafka.common.serialization.StringSerializer) CommandNotificationSerializer(org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer) KafkaNotificationRegistrationClient(org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient) Before(org.junit.Before)

Example 2 with CommandNotificationSerializer

use of org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer in project incubator-rya by apache.

the class PeriodicCommandNotificationConsumerIT method kafkaNotificationMillisProviderTest.

@Test
public void kafkaNotificationMillisProviderTest() throws InterruptedException {
    BasicConfigurator.configure();
    final BlockingQueue<TimestampedNotification> notifications = new LinkedBlockingQueue<>();
    final Properties props = createKafkaConfig();
    final KafkaProducer<String, CommandNotification> producer = new KafkaProducer<>(props);
    final String topic = rule.getKafkaTopicName();
    rule.createTopic(topic);
    registration = new KafkaNotificationRegistrationClient(topic, producer);
    coord = new PeriodicNotificationCoordinatorExecutor(1, notifications);
    provider = new KafkaNotificationProvider(topic, new StringDeserializer(), new CommandNotificationSerializer(), props, coord, 1);
    provider.start();
    registration.addNotification("1", 1000, 0, TimeUnit.MILLISECONDS);
    Thread.sleep(4000);
    // check that notifications are being added to the blocking queue
    Assert.assertEquals(true, notifications.size() > 0);
    registration.deleteNotification("1");
    Thread.sleep(2000);
    final int size = notifications.size();
    // sleep for 2 seconds to ensure no more messages being produced
    Thread.sleep(2000);
    Assert.assertEquals(size, notifications.size());
    tearDown();
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) TimestampedNotification(org.apache.rya.periodic.notification.notification.TimestampedNotification) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Properties(java.util.Properties) CommandNotificationSerializer(org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer) PeriodicNotificationCoordinatorExecutor(org.apache.rya.periodic.notification.coordinator.PeriodicNotificationCoordinatorExecutor) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) KafkaNotificationRegistrationClient(org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient) Test(org.junit.Test)

Example 3 with CommandNotificationSerializer

use of org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer in project incubator-rya by apache.

the class PeriodicCommandNotificationConsumerIT method kafkaNotificationProviderTest.

@Test
public void kafkaNotificationProviderTest() throws InterruptedException {
    BasicConfigurator.configure();
    final BlockingQueue<TimestampedNotification> notifications = new LinkedBlockingQueue<>();
    final Properties props = createKafkaConfig();
    final KafkaProducer<String, CommandNotification> producer = new KafkaProducer<>(props);
    final String topic = rule.getKafkaTopicName();
    rule.createTopic(topic);
    registration = new KafkaNotificationRegistrationClient(topic, producer);
    coord = new PeriodicNotificationCoordinatorExecutor(1, notifications);
    provider = new KafkaNotificationProvider(topic, new StringDeserializer(), new CommandNotificationSerializer(), props, coord, 1);
    provider.start();
    registration.addNotification("1", 1, 0, TimeUnit.SECONDS);
    Thread.sleep(4000);
    // check that notifications are being added to the blocking queue
    Assert.assertEquals(true, notifications.size() > 0);
    registration.deleteNotification("1");
    Thread.sleep(2000);
    final int size = notifications.size();
    // sleep for 2 seconds to ensure no more messages being produced
    Thread.sleep(2000);
    Assert.assertEquals(size, notifications.size());
    tearDown();
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) TimestampedNotification(org.apache.rya.periodic.notification.notification.TimestampedNotification) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Properties(java.util.Properties) CommandNotificationSerializer(org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer) PeriodicNotificationCoordinatorExecutor(org.apache.rya.periodic.notification.coordinator.PeriodicNotificationCoordinatorExecutor) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) KafkaNotificationRegistrationClient(org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient) Test(org.junit.Test)

Aggregations

KafkaNotificationRegistrationClient (org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient)3 CommandNotificationSerializer (org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer)3 Properties (java.util.Properties)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)2 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)2 PeriodicNotificationCoordinatorExecutor (org.apache.rya.periodic.notification.coordinator.PeriodicNotificationCoordinatorExecutor)2 CommandNotification (org.apache.rya.periodic.notification.notification.CommandNotification)2 TimestampedNotification (org.apache.rya.periodic.notification.notification.TimestampedNotification)2 Test (org.junit.Test)2 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 Before (org.junit.Before)1