-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Subscribe and Managed Subscribe examples #60
Changes from 5 commits
7158d1f
d57f4c5
195afe3
03f2d2f
929f079
1023318
a17ea27
379f313
02a91bb
688c9ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ | |
import java.io.*; | ||
import java.nio.ByteBuffer; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.avro.Schema; | ||
import org.apache.avro.generic.GenericData; | ||
import org.apache.avro.generic.GenericDatumReader; | ||
import org.apache.avro.generic.GenericRecord; | ||
import org.apache.avro.generic.GenericRecordBuilder; | ||
|
@@ -25,6 +25,8 @@ | |
|
||
import io.grpc.*; | ||
|
||
import static utility.EventParser.getFieldListFromBitmap; | ||
|
||
/** | ||
* The CommonContext class provides a list of member variables and functions that is used across | ||
* all examples for various purposes like setting up the HttpClient, CallCredentials, stubs for | ||
|
@@ -265,6 +267,26 @@ public static GenericRecord deserialize(Schema schema, ByteString payload) throw | |
return reader.read(null, decoder); | ||
} | ||
|
||
public static void processAndPrintChangedFields(Schema writerSchema, GenericRecord record) throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that we print only the changed fields. Is it possible to add a comment similar to: // This method expands the changedFields bitmap field in ChangeEventHeader. To expand the other bitmap fields, diffFields and nulledFields, modify this code. |
||
try { | ||
List<String> changedFields = getFieldListFromBitmap(writerSchema, | ||
(GenericData.Record) record.get("ChangeEventHeader"), "changedFields"); | ||
if (!changedFields.isEmpty()) { | ||
logger.info("============================"); | ||
logger.info(" Changed Fields "); | ||
logger.info("============================"); | ||
for (String field : changedFields) { | ||
logger.info(field); | ||
} | ||
logger.info("============================\n"); | ||
} else { | ||
logger.info("No ChangedFields found\n"); | ||
} | ||
} catch (Exception e) { | ||
logger.info("Trying to process ChangedFields on unsupported events or no ChangedFields found. Error: " + e.getMessage() + "\n"); | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to setup Subscribe configurations in some examples. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ TENANT_ID: null | |
ACCESS_TOKEN: null | ||
|
||
# ========================= | ||
# Optional configurations: | ||
# Optional Configurations: | ||
# ========================= | ||
# Topic to publish/subscribe to (default: /event/Order_Event__e) | ||
TOPIC: null | ||
|
@@ -43,6 +43,8 @@ NUMBER_OF_EVENTS_IN_FETCHREQUEST: null | |
REPLAY_PRESET: null | ||
# Replay ID in ByteString | ||
REPLAY_ID: null | ||
# Flag to enable/disable ChangedFields processing in Subscribe and ManagedSubscribe examples for CDC events (default: false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment on another thread about this. |
||
PROCESS_CHANGED_FIELDS: null | ||
|
||
# ManagedSubscribe RPC parameters | ||
# For ManagedSubscribe.java, either supply the developer name or the ID of ManagedEventSubscription | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ChangeDataCapture -> Change Data Capture
@knhage thoughts about the wording here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sidd0610 This should be for all the bitmap fields in ChangeEventHeader:
changedFields, diffFields, and nulledFields
This is doc'd in Event Deserialization Considerations.
So I suggest rewording to:
PROCESS_CHANGE_EVENT_HEADER_FIELDS
: Specify whether the Subscribe or ManagedSubscribe client process the change data capture event bitmap fields in ChangeEventHeader. See Event Deserialization Considerations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sidd0610 I just realized that the client expands only the changedFields bitmap field. Maybe we can change the text to the following:
PROCESS_CHANGE_EVENT_HEADER_FIELDS
: Specify whether the Subscribe or ManagedSubscribe client process the change data capture event bitmap fields in ChangeEventHeader. In this sample, only thechangedFields
field is expanded. To expand thediffFields
andnulledFields
header fields, modify the sample code. See Event Deserialization Considerations.