Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BD0F0200C2F for ; Mon, 6 Mar 2017 19:41:38 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id BB636160B76; Mon, 6 Mar 2017 18:41:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DDB66160B84 for ; Mon, 6 Mar 2017 19:41:37 +0100 (CET) Received: (qmail 52591 invoked by uid 500); 6 Mar 2017 18:41:37 -0000 Mailing-List: contact commits-help@beam.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@beam.apache.org Delivered-To: mailing list commits@beam.apache.org Received: (qmail 52581 invoked by uid 99); 6 Mar 2017 18:41:37 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2017 18:41:37 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id A9BB1184928 for ; Mon, 6 Mar 2017 18:41:36 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.547 X-Spam-Level: X-Spam-Status: No, score=-1.547 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-2.999, SPF_NEUTRAL=0.652] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id ze6ew1F_MfH2 for ; Mon, 6 Mar 2017 18:41:35 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 032E05FC75 for ; Mon, 6 Mar 2017 18:41:34 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id C2F91E0933 for ; Mon, 6 Mar 2017 18:41:33 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 2F9A724176 for ; Mon, 6 Mar 2017 18:41:33 +0000 (UTC) Date: Mon, 6 Mar 2017 18:41:33 +0000 (UTC) From: "Raghu Angadi (JIRA)" To: commits@beam.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (BEAM-1573) KafkaIO does not allow using Kafka serializers and deserializers MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 06 Mar 2017 18:41:38 -0000 [ https://issues.apache.org/jira/browse/BEAM-1573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15896948#comment-15896948 ] Raghu Angadi edited comment on BEAM-1573 at 3/6/17 6:40 PM: ------------------------------------------------------------ @peay, There are two levels of solutions to deserializer (and serializer): # Reasonable ways to make use of custom Kafka deserializers & serializers ** This is very feasible now, including the case when you are reading from multiple topics. # Update to KafkaIO API to pass Kafka serializers directly to the Kafka consumer. ** We might end up doing this, not exactly how you proposed, but rather replacing coders with Kafka (de)serializers. There is no need to include both I think. ** There is a discussion on Beam mailing lists about removing use of coders directly in sources and other places and that might be right time to add this support. (cc [~jkff]) Are you more interested 1 or 2? One way to use any Kafka serializer (for (1)): {code} PCollection kafkaRecords = // Note that KafkaRecord include topic name, partition etc. pipeline .apply(KafkaIO.read() .withBootstrapServers("broker_1:9092,broker_2:9092") .withTopics(ImmutableList.of("topic_a"))); kafkaRecords.apply( ParDo.of(new DoFn, MyAvroRecord>) { private final Map config = // config private transient Deserializer kafkaDeserializer; @Setup public void setup() { kafkaDeserializer = new MyDeserializer(); kafkaDeserializer.configure(config) // kafka config (serializable map) } @ProcessElement public void procesElement(Context context) { MyAvroRecord record = kafkaDeserializer.deserialize(context.element().getTopic(), context.element().getValue()) context.output(record); } @TearDown public void tearDown() { kafkaDeserializer.close(); } })) {code} was (Author: rangadi): @peay, There are two levels of solutions to deserializer (and serializer): # Reasonable ways to use of custom Kafka deserializers & serializers ** This is very feasible now, including the case when you are reading from multiple topics. # Update to KafkaIO API to pass Kafka serializers directly to the Kafka consumer. ** We might end up doing this, not exactly how you proposed, but rather replacing coders with Kafka (de)serializers. There is no need to include both I think. ** There is a discussion on Beam mailing lists about removing use of coders directly in sources and other places and that might be right time to add this support. (cc [~jkff]) Are you more interested 1 or 2? One way to use any Kafka serializer (for (1)): {code} PCollection kafkaRecords = // Note that KafkaRecord include topic name, partition etc. pipeline .apply(KafkaIO.read() .withBootstrapServers("broker_1:9092,broker_2:9092") .withTopics(ImmutableList.of("topic_a"))); kafkaRecords.apply( ParDo.of(new DoFn, MyAvroRecord>) { private final Map config = // config private transient Deserializer kafkaDeserializer; @Setup public void setup() { kafkaDeserializer = new MyDeserializer(); kafkaDeserializer.configure(config) // kafka config (serializable map) } @ProcessElement public void procesElement(Context context) { MyAvroRecord record = kafkaDeserializer.deserialize(context.element().getTopic(), context.element().getValue()) context.output(record); } @TearDown public void tearDown() { kafkaDeserializer.close(); } })) {code} > KafkaIO does not allow using Kafka serializers and deserializers > ---------------------------------------------------------------- > > Key: BEAM-1573 > URL: https://issues.apache.org/jira/browse/BEAM-1573 > Project: Beam > Issue Type: Improvement > Components: sdk-java-extensions > Affects Versions: 0.4.0, 0.5.0 > Reporter: peay > Assignee: Raghu Angadi > Priority: Minor > > KafkaIO does not allow to override the serializer and deserializer settings of the Kafka consumer and producers it uses internally. Instead, it allows to set a `Coder`, and has a simple Kafka serializer/deserializer wrapper class that calls the coder. > I appreciate that allowing to use Beam coders is good and consistent with the rest of the system. However, is there a reason to completely disallow to use custom Kafka serializers instead? > This is a limitation when working with an Avro schema registry for instance, which requires custom serializers. One can write a `Coder` that wraps a custom Kafka serializer, but that means two levels of un-necessary wrapping. > In addition, the `Coder` abstraction is not equivalent to Kafka's `Serializer` which gets the topic name as input. Using a `Coder` wrapper would require duplicating the output topic setting in the argument to `KafkaIO` and when building the wrapper, which is not elegant and error prone. -- This message was sent by Atlassian JIRA (v6.3.15#6346)