org.apache.kafka.connect.sink.SinkConnector Java Examples

The following examples show how to use org.apache.kafka.connect.sink.SinkConnector. 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: IgniteSinkConnectorTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates properties for test sink connector.
 *
 * @param topics Topics.
 * @return Test sink connector properties.
 */
private Map<String, String> makeSinkProps(String topics) {
    Map<String, String> props = new HashMap<>();

    props.put(SinkConnector.TOPICS_CONFIG, topics);
    props.put(ConnectorConfig.TASKS_MAX_CONFIG, "2");
    props.put(ConnectorConfig.NAME_CONFIG, "test-sink-connector");
    props.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, IgniteSinkConnectorMock.class.getName());
    props.put(IgniteSinkConstants.CACHE_NAME, "testCache");
    props.put(IgniteSinkConstants.CACHE_ALLOW_OVERWRITE, "true");
    props.put(IgniteSinkConstants.CACHE_CFG_PATH, "example-ignite.xml");
    props.put(IgniteSinkConstants.SINGLE_TUPLE_EXTRACTOR_CLASS,
        "org.apache.ignite.stream.kafka.connect.IgniteSinkConnectorTest$TestExtractor");

    return props;
}
 
Example #2
Source File: PluginLoader.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
Set<Class<? extends SinkConnector>> findSinkConnectors() {
  return this.reflections.getSubTypesOf(SinkConnector.class)
      .stream()
      .filter(c -> c.getName().startsWith(pkg.getName()))
      .filter(c -> Modifier.isPublic(c.getModifiers()))
      .filter(c -> !Modifier.isAbstract(c.getModifiers()))
      .filter((Predicate<Class<? extends SinkConnector>>) aClass -> Arrays.stream(aClass.getConstructors())
          .filter(c -> Modifier.isPublic(c.getModifiers()))
          .anyMatch(c -> c.getParameterCount() == 0))
      .collect(Collectors.toSet());
}
 
Example #3
Source File: PluginLoader.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
public Plugin load() {
  ImmutablePlugin.Builder builder = ImmutablePlugin.builder()
      .from(notes(this.pkg))
      .pluginName(AnnotationHelper.pluginName(this.pkg))
      .pluginOwner(AnnotationHelper.pluginOwner(this.pkg));
  List<Plugin.Transformation> transformations = loadTransformations();
  builder.addAllTransformations(transformations);
  List<Plugin.SinkConnector> sinkConnectors = loadSinkConnectors();
  builder.addAllSinkConnectors(sinkConnectors);
  List<Plugin.SourceConnector> sourceConnectors = loadSourceConnectors();
  builder.addAllSourceConnectors(sourceConnectors);
  List<Plugin.Converter> converters = loadConverters();
  builder.addAllConverters(converters);
  return builder.build();
}
 
Example #4
Source File: PluginLoaderTest.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void findSinkConnectors() {
  final Set<Class<? extends SinkConnector>> expected = ImmutableSet.of(
      TestSinkConnector.class,
      NoDocTestSinkConnector.class
  );
  final Set<Class<? extends SinkConnector>> actual = pluginLoader.findSinkConnectors();

  assertEquals(expected, actual);
}
 
Example #5
Source File: FileStreamSinkConnectorTest.java    From kafka-connector-skeleton with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    connector = new FileStreamSinkConnector();
    ctx = PowerMock.createMock(ConnectorContext.class);
    connector.initialize(ctx);

    sinkProperties = new HashMap<>();
    sinkProperties.put(SinkConnector.TOPICS_CONFIG, MULTIPLE_TOPICS);
    sinkProperties.put(FileStreamSinkConnector.FILE_CONFIG, FILENAME);
}
 
Example #6
Source File: IgniteSinkConnector.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * A sink lifecycle method. Validates grid-specific sink properties.
 *
 * @param props Sink properties.
 */
@Override public void start(Map<String, String> props) {
    configProps = props;

    try {
        A.notNullOrEmpty(configProps.get(SinkConnector.TOPICS_CONFIG), "topics");
        A.notNullOrEmpty(configProps.get(IgniteSinkConstants.CACHE_NAME), "cache name");
        A.notNullOrEmpty(configProps.get(IgniteSinkConstants.CACHE_CFG_PATH), "path to cache config file");
    }
    catch (IllegalArgumentException e) {
        throw new ConnectException("Cannot start IgniteSinkConnector due to configuration error", e);
    }
}
 
Example #7
Source File: MQSinkConnectorTest.java    From kafka-connect-mq-sink with Apache License 2.0 4 votes vote down vote up
@Test
public void testConnectorType() {
    Connector connector = new MQSinkConnector();
    assertTrue(SinkConnector.class.isAssignableFrom(connector.getClass()));
}