push
This commit is contained in:
4
java-producer-consumer/build.sh
Executable file
4
java-producer-consumer/build.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#! /bin/bash
|
||||
mvn package
|
||||
echo 3 | . $(dirname "${BASH_SOURCE[0]}")/../kafka*/start.sh
|
||||
java -jar output/my-app-1.0-SNAPSHOT.jar
|
||||
53
java-producer-consumer/my-app.iml
Executable file
53
java-producer-consumer/my-app.iml
Executable file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.qualtrics.qsl:serialization:2.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.qualtrics:vbeacon:0.1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.avro:avro:1.8.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.thoughtworks.paranamer:paranamer:2.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.xerial.snappy:snappy-java:1.1.1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.tukaani:xz:1.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:findbugs-annotations:3.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:fluent-hc:4.5.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.json:json:20180130" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.qualtrics.qmp:qmp-client:0.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.kafka:kafka_2.12:1.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.yammer.metrics:metrics-core:2.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.scala-lang:scala-library:2.12.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.101tec:zkclient:0.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.zookeeper:zookeeper:3.4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.16" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.kafka:kafka-clients:1.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.lz4:lz4-java:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.sf.jopt-simple:jopt-simple:5.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:24.0-jre" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.checkerframework:checker-compat-qual:2.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.datadoghq:java-dogstatsd-client:2.5" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
1
java-producer-consumer/one_consumer.sh
Executable file
1
java-producer-consumer/one_consumer.sh
Executable file
@@ -0,0 +1 @@
|
||||
SCHEMA_REGISTRY_URL="localhost:8081" java -jar output/my-app-1.0-SNAPSHOT.jar cons my-topic-1
|
||||
1
java-producer-consumer/one_producer.sh
Executable file
1
java-producer-consumer/one_producer.sh
Executable file
@@ -0,0 +1 @@
|
||||
SCHEMA_REGISTRY_URL="localhost:8081" java -jar output/my-app-1.0-SNAPSHOT.jar prod my-topic-1
|
||||
80
java-producer-consumer/pom.xml
Executable file
80
java-producer-consumer/pom.xml
Executable file
@@ -0,0 +1,80 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mycompany.app</groupId>
|
||||
<artifactId>my-app</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>my-app</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qualtrics.qsl</groupId>
|
||||
<artifactId>serialization</artifactId>
|
||||
<version>0.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qualtrics.qmp</groupId>
|
||||
<artifactId>qmp-client</artifactId>
|
||||
<version>0.2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>libs-release-local</id>
|
||||
<name>Qualtrics Local Lib Releases</name>
|
||||
<url>http://artifactory.eng.qops.net:8081/artifactory/libs-release-local</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
<checksumPolicy>fail</checksumPolicy>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<build><plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>output/lib</outputDirectory>
|
||||
<overWriteReleases>false</overWriteReleases>
|
||||
<overWriteSnapshots>false</overWriteSnapshots>
|
||||
<overWriteIfNewer>true</overWriteIfNewer>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<outputDirectory>output</outputDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib</classpathPrefix>
|
||||
<mainClass>com.mycompany.app.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins></build>
|
||||
</project>
|
||||
182
java-producer-consumer/src/main/java/com/mycompany/app/App.java
Executable file
182
java-producer-consumer/src/main/java/com/mycompany/app/App.java
Executable file
@@ -0,0 +1,182 @@
|
||||
package com.mycompany.app;
|
||||
|
||||
import com.qualtrics.client.model.*;
|
||||
import com.qualtrics.qsl.model.*;
|
||||
import com.qualtrics.qsl.schema.Singleton;
|
||||
import org.apache.avro.Schema;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static String schId = "qmp.payload.v1";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String topic = "testtopic";
|
||||
if (args.length >= 2) {
|
||||
topic = args[1];
|
||||
}
|
||||
setup();
|
||||
if (args.length > 0) {
|
||||
if (args[0].startsWith("cons")) {
|
||||
System.out.println("---CONSUMING "+ topic);
|
||||
consume(topic);
|
||||
Scanner in = new Scanner(System.in);
|
||||
byte c = in.nextByte();
|
||||
System.out.println("---STOPPING CONSUMER");
|
||||
} else if (args[0].startsWith("prod")) {
|
||||
System.out.println("---PRODUCING "+ topic);
|
||||
produce(topic, 1, 10000000);
|
||||
System.out.println("---STOPPING PRODUCER");
|
||||
}
|
||||
} else {
|
||||
System.out.println("---Producing and consuming a few");
|
||||
produce(topic, 1, 5);
|
||||
consume(topic);
|
||||
}
|
||||
}
|
||||
|
||||
static void setup() {
|
||||
try {
|
||||
QMManagerSingleton.INSTANCE.registerApplication("HelloWurl");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
QMPClientFactorySingleton.INSTANCE.registerApplication("HelloWurl");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void produce(String topic, int delay, int max) throws Exception {
|
||||
QMManager manager;
|
||||
QMWriter writer;
|
||||
Schema sch = Singleton.INSTANCE.getSchemaManager().retrieveSchema(schId);
|
||||
QMessage message = null;
|
||||
|
||||
try {
|
||||
manager = QMManagerSingleton.INSTANCE.get();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
writer = manager.createWriter(schId);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
message = writer.createMessage();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
message.set("body1", "hello from java");
|
||||
|
||||
QMPClientFactory factory;
|
||||
QProducer producer;
|
||||
|
||||
try {
|
||||
factory = QMPClientFactorySingleton.INSTANCE.get();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
producer = factory.createProducer(QProducerType.BULK, topic);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
QProducerHandler handle = new handler();
|
||||
for(int i=0; i<max; i++) {
|
||||
message = writer.createMessage();
|
||||
producer.put(message, handle);
|
||||
Thread.sleep(1000*delay);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
Thread.sleep(1000*10);
|
||||
}
|
||||
|
||||
static void consume(String topic) throws Exception {
|
||||
QMManager manager;
|
||||
QMReader reader;
|
||||
Schema sch = Singleton.INSTANCE.getSchemaManager().retrieveSchema(schId);
|
||||
|
||||
try {
|
||||
manager = QMManagerSingleton.INSTANCE.get();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
reader = manager.createReader(schId);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
|
||||
QMPClientFactory factory;
|
||||
QConsumer consumer;
|
||||
|
||||
try {
|
||||
factory = QMPClientFactorySingleton.INSTANCE.get();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
consumer = factory.createConsumer(QConsumerType.BULK, topic, "javagroup", 1, reader);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
consumer.start(new chandler());
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
Thread.sleep(1000*10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class handler implements QProducerHandler {
|
||||
public int procount = 0;
|
||||
public void handlePut(QProducerFailedToSend var1, QMessage var2) {
|
||||
procount++;
|
||||
System.out.printf("\r %d ", procount);
|
||||
/*
|
||||
System.out.println(var1);
|
||||
System.out.print(var2.getMessageId());
|
||||
System.out.println(var2);
|
||||
//System.exit(0);
|
||||
*/
|
||||
}
|
||||
}
|
||||
class chandler implements MessageProcessor {
|
||||
public int concount = 0;
|
||||
public void process(QMessage message) {
|
||||
concount++;
|
||||
System.out.printf("\r %d ", concount);
|
||||
/*
|
||||
System.out.print(message.getMessageId());
|
||||
System.out.println(message.get("body1"));
|
||||
//System.exit(0);
|
||||
*/
|
||||
}
|
||||
}
|
||||
38
java-producer-consumer/src/test/java/com/mycompany/app/AppTest.java
Executable file
38
java-producer-consumer/src/test/java/com/mycompany/app/AppTest.java
Executable file
@@ -0,0 +1,38 @@
|
||||
package com.mycompany.app;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user