-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #73
- Loading branch information
Showing
6 changed files
with
210 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
imixs-adapters-kafka/src/main/java/org/imixs/workflow/kafka/ConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.imixs.workflow.kafka; | ||
|
||
import java.io.Serializable; | ||
import java.util.logging.Logger; | ||
|
||
import javax.ejb.Stateless; | ||
|
||
/** | ||
* The ConfigService is used to provide static String and environment access methods. | ||
* | ||
* @version 1.0 | ||
* @author rsoika | ||
* | ||
*/ | ||
@Stateless | ||
public class ConfigService implements Serializable { | ||
|
||
public static final String ENV_KAFKA_BROKERS = "KAFKA_BROKERS"; | ||
public static final String ENV_KAFKA_CLIENTID = "KAFKA_CLIENTID"; | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private static Logger logger = Logger.getLogger(ConfigService.class.getName()); | ||
|
||
|
||
/** | ||
* Returns a environment variable. An environment variable can be provided as a | ||
* System property. | ||
* | ||
* @param env | ||
* - environment variable name | ||
* @param defaultValue | ||
* - optional default value | ||
* @return value | ||
*/ | ||
public static String getEnv(String env, String defaultValue) { | ||
logger.finest("......read env: " + env); | ||
String result = System.getenv(env); | ||
if (result == null || result.isEmpty()) { | ||
result = defaultValue; | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
imixs-adapters-kafka/src/test/java/org/imixs/workflow/kafka/TestProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.imixs.workflow.kafka; | ||
|
||
import java.util.Properties; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.Producer; | ||
import org.apache.kafka.clients.producer.ProducerConfig; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.apache.kafka.clients.producer.RecordMetadata; | ||
import org.apache.kafka.common.serialization.LongSerializer; | ||
import org.apache.kafka.common.serialization.StringSerializer; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import junit.framework.Assert; | ||
|
||
/** | ||
* This test verifies the IBAN regex | ||
* | ||
* @author rsoika | ||
* | ||
*/ | ||
public class TestProducer { | ||
|
||
Producer<Long, String> producer; | ||
|
||
private static Logger logger = Logger.getLogger(TestProducer.class.getName()); | ||
|
||
|
||
@Before | ||
public void setup() { | ||
Properties props = new Properties(); | ||
|
||
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9094"); | ||
|
||
|
||
props.put(ProducerConfig.CLIENT_ID_CONFIG,"Imixs-Workflow1"); | ||
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, LongSerializer.class.getName()); | ||
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); | ||
|
||
|
||
|
||
// here we wait maximum one second if the topic is present in the metadata (default is 60000) | ||
props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG,1000); | ||
// props.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, | ||
// CustomPartitioner.class.getName()); | ||
producer = new KafkaProducer<>(props); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
producer.close(); | ||
} | ||
|
||
/** | ||
* test the fieldlist of the first line of the file | ||
*/ | ||
@Test | ||
public void testSendMessages() { | ||
|
||
ProducerRecord<Long, String> record = new ProducerRecord<Long, String>("1.0.1", "some data test..."); | ||
|
||
try { | ||
RecordMetadata metadata = producer.send(record).get(); | ||
logger.info("...Imixs-Workflow Event sent to partition " + metadata.partition() | ||
+ " with offset " + metadata.offset()); | ||
} | ||
|
||
catch (ExecutionException e) { | ||
logger.info("Error in sending record: " + e.getMessage()); | ||
Assert.fail(); | ||
} | ||
|
||
catch (InterruptedException e) { | ||
System.out.println("Error in sending record: " + e.getMessage()); | ||
Assert.fail(); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
} |