-
Notifications
You must be signed in to change notification settings - Fork 0
Update pubsub consumer #27
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 pubsub consumer #27
Conversation
Pull Request Review: Google Pub/Sub V2 IntegrationSummaryThis PR introduces a new ✅ StrengthsCode Quality
Design Decisions
🔍 Issues & Concerns🔴 Critical Issues1. Context Lifecycle Management (High Priority)Location: ctx: context.Background(),Issue: The consumer stores
Recommendation: // Remove ctx field from struct
// Use the context passed to Process() for publishing
// Create a new context with timeout for Close() operations:
func (c *PublishToGooglePubSubV2) Close() error {
// Use context with timeout for graceful shutdown
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Use ctx for cleanup operations...
}2. Missing Helper Function DefinitionLocation: The code uses Recommendation: Extract common helper functions to a shared file like func getStringConfig(config map[string]interface{}, key, defaultValue string) string {
if val, ok := config[key].(string); ok {
return val
}
return defaultValue
}3. Suspicious .gitignore EntryLocation: Issue: This appears to be a Stellar account address followed by
Recommendation: Remove this line from
|
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.
Pull Request Overview
This pull request introduces a new V2 format for publishing Stellar payment events to Google Pub/Sub, with improved message structure and enhanced downstream integration capabilities. The implementation adds a new consumer type, comprehensive documentation, and example configurations to guide adoption.
Key Changes:
- Added
PublishToGooglePubSubV2consumer with structured three-level message format (chainIdentifier, payload, details) and improved field naming - Comprehensive documentation covering V2 format, migration from V1, local testing with emulator, and code examples in TypeScript and Python
- Example configuration demonstrating V2 consumer usage with environment variable support and emulator testing
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| main.go | Registers new PublishToGooglePubSubV2 consumer type in the consumer factory |
| consumer/consumer_publish_to_google_pubsub_v2.go | Implements V2 consumer with structured message format, flexible authentication, and message attributes for filtering |
| docs/google-pubsub-v2-format.md | Comprehensive documentation of V2 format, configuration, migration guide, and usage examples |
| config/examples/kwickbit-payments-pubsub-v2.yaml | Example pipeline configuration demonstrating V2 consumer with environment variable overrides |
| config/examples/rpc-streaming-mode.yaml | Clarified that poll_interval is required in streaming mode |
| config/base/usdc_transfers_rpc.yaml | Improved topic filter documentation to specify XDR-encoded format |
| config/base/test_websocket_client.py | Removed unused time import |
| .gitignore | Added contract address file pattern to ignore list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ProjectID: getStringConfig(config, "project_id", ""), | ||
| TopicID: getStringConfig(config, "topic_id", ""), | ||
| ChainIdentifier: ChainIdentifier(getStringConfig(config, "chain_identifier", string(ChainIdentifierStellarTestnet))), | ||
| CredentialsJSON: getStringConfig(config, "credentials_json", ""), | ||
| CredentialsFile: getStringConfig(config, "credentials_file", ""), |
Copilot
AI
Nov 19, 2025
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.
The getStringConfig helper function is used but not defined in this file. This will cause a compilation error. The function needs to be added to this file, similar to how it's defined in consumer_save_event_payment_to_postgresql.go:
func getStringConfig(config map[string]interface{}, key, defaultValue string) string {
if val, ok := config[key].(string); ok {
return val
}
return defaultValue
}
Pull Request Review - PublishToGooglePubSubV2 ConsumerI've reviewed PR #27 which introduces a new V2 message format for Google Pub/Sub integration. Here's my detailed feedback: ✅ Strengths
🔧 Issues & Recommendations1. Code Duplication - getStringConfig Helper FunctionIssue: The Impact:
Recommendation: Create a shared // consumer/helpers.go
package consumer
func getStringConfig(config map[string]interface{}, key, defaultValue string) string {
if val, ok := config[key].(string); ok {
return val
}
return defaultValue
}
func getIntConfig(config map[string]interface{}, key string, defaultValue int) int {
if val, ok := config[key].(int); ok {
return val
}
if val, ok := config[key].(float64); ok {
return int(val)
}
return defaultValue
}2. Inconsistent Mutex Usage Between V1 and V2Issue:
Recommendation:
3. Context Handling InconsistencyIssue:
Recommendation: V2's approach is better (don't store context as field). Consider updating V1 to match. 4. Missing Resource Cleanup VerificationIssue: The Current Code (line 265): c.topic.Stop()Recommendation: While // Stop the topic (flush any pending messages)
// Note: topic.Stop() blocks until all pending publishes complete
if c.topic != nil {
log.Printf("PublishToGooglePubSubV2: Stopping topic to flush pending messages...")
c.topic.Stop()
log.Printf("PublishToGooglePubSubV2: Topic stopped successfully")
}5. Type Conversion Potential IssueIssue: At line 199-200, converting Amount: strconv.FormatUint(eventPayment.Amount, 10),
RoyaltyFee: strconv.FormatUint(eventPayment.RoyaltyAmount, 10),This is correct and matches the documented V2 format. However, the documentation could clarify the precision preservation rationale. Recommendation: Ensure downstream consumers are aware these are string-encoded integers, not floating point. The docs do mention this, which is good. 6. Configuration Validation - Missing Topic Creation Permission CheckMinor Issue: The code attempts to create topics if they don't exist (lines 165-171), but doesn't validate if the service account has Recommendation: Add a note in the documentation about required permissions, or make topic auto-creation optional via config: auto_create_topic: false # Default true for backward compatibility🧪 Test Coverage ConcernsCritical Issue: No test files exist for this consumer ( Recommendation: Add unit tests covering:
Example test structure: func TestNewPublishToGooglePubSubV2_InvalidChainIdentifier(t *testing.T) {
config := map[string]interface{}{
"project_id": "test-project",
"topic_id": "test-topic",
"chain_identifier": "InvalidChain",
}
_, err := NewPublishToGooglePubSubV2(config)
if err == nil {
t.Error("Expected error for invalid chain identifier")
}
}🔒 Security Considerations
📊 Performance
📝 Minor Code Quality Issues
log.Printf("PublishToGooglePubSubV2: Published payment_id=%s, chain=%s, block=%d, tx=%s, messageID=%s",
eventPayment.PaymentID, c.ChainIdentifier, eventPayment.BlockHeight, eventPayment.TxHash[:8], messageID)
📋 Config File Reviewkwickbit-payments-pubsub-v2.yaml:
🎯 SummaryOverall Assessment: This is a well-implemented feature with excellent documentation. The code quality is good and follows established patterns in the codebase. Must Fix Before Merge:
Should Fix: Nice to Have: Migration Compatibility: The V2 format is well-designed for coexistence with V1. The Recommendation: Request changes to address items #1 and #2, then approve after fixes. |
This pull request introduces support for publishing Stellar payment events to Google Pub/Sub using a new V2 message format, designed for improved downstream integration and message filtering. The main changes include the implementation of the
PublishToGooglePubSubV2consumer, comprehensive documentation for the new format, and example configuration files to guide adoption. Minor clarifications and improvements were also made to existing pipeline configurations.Google Pub/Sub V2 Integration
PublishToGooglePubSubV2, inconsumer_publish_to_google_pubsub_v2.go. This supports publishing payment events in a structured V2 format, with improved field naming, message attributes, and flexible authentication via config or environment variables.main.goto support the new consumer type, enabling it to be used in pipeline configurations.Documentation
docs/google-pubsub-v2-format.md, describing the V2 message format, configuration options, migration steps from V1, usage examples, and troubleshooting tips for Google Pub/Sub integration.Configuration Examples
kwickbit-payments-pubsub-v2.yaml, demonstrating how to use the new V2 consumer and message format, including environment variable overrides and emulator support for local testing.Clarifications and Minor Improvements
usdc_transfers_rpc.yamlto specify XDR-encoded filters.rpc-streaming-mode.yamlto note thatpoll_intervalis required.timeimport fromtest_websocket_client.pyfor code cleanliness.