-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Salesforce Destination Using Pubsub (#146)
* Draft salesforce destination nit * Cleanup code * Nit * lint * refactor tests * Refactor Pubsub Client * Cleanup * Update refactor pubusb + add utisl * Change fmt.errors to errors, modify validate on dest * Update headers, cleanup some fields, lint * Update errors and add retry on topics * lint cleanup * publish records one by one instead of batches * add retry on schema prepare * refactor write and publish * Update license date, config, field checks * Check fields and dates * Update configs * Update source_test.go
- Loading branch information
1 parent
6a9c0ad
commit 9431187
Showing
19 changed files
with
878 additions
and
407 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
// Copyright © 2024 Meroxa, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package destination | ||
|
||
import ( | ||
config "github.com/conduitio-labs/conduit-connector-salesforce/config" | ||
"github.com/conduitio/conduit-commons/opencdc" | ||
) | ||
|
||
type TopicFn func(opencdc.Record) (string, error) | ||
|
||
//go:generate paramgen -output=paramgen_config.go Config | ||
type Config struct { | ||
config.Config | ||
|
||
// Topic is Salesforce event or topic to write record | ||
TopicName string `json:"topicName" validate:"required"` | ||
} |
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,105 @@ | ||
// Copyright © 2024 Meroxa, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package destination | ||
|
||
import ( | ||
"context" | ||
|
||
pubsub "github.com/conduitio-labs/conduit-connector-salesforce/pubsub" | ||
"github.com/conduitio/conduit-commons/config" | ||
"github.com/conduitio/conduit-commons/opencdc" | ||
sdk "github.com/conduitio/conduit-connector-sdk" | ||
"github.com/go-errors/errors" | ||
) | ||
|
||
var _ client = (*pubsub.Client)(nil) | ||
|
||
type client interface { | ||
Stop(context.Context) | ||
Close(context.Context) error | ||
Write(context.Context, opencdc.Record) error | ||
Initialize(context.Context, []string) error | ||
} | ||
|
||
type Destination struct { | ||
sdk.UnimplementedDestination | ||
client client | ||
config Config | ||
} | ||
|
||
func NewDestination() sdk.Destination { | ||
return sdk.DestinationWithMiddleware(&Destination{}, sdk.DefaultDestinationMiddleware()...) | ||
} | ||
|
||
func (d *Destination) Parameters() config.Parameters { | ||
return d.config.Parameters() | ||
} | ||
|
||
func (d *Destination) Configure(ctx context.Context, cfg config.Config) error { | ||
if err := sdk.Util.ParseConfig( | ||
ctx, | ||
cfg, | ||
&d.config, | ||
NewDestination().Parameters(), | ||
); err != nil { | ||
return errors.Errorf("failed to parse config: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (d *Destination) Open(ctx context.Context) error { | ||
client, err := pubsub.NewGRPCClient(ctx, d.config.Config, "publish") | ||
if err != nil { | ||
return errors.Errorf("could not create GRPCClient: %w", err) | ||
} | ||
|
||
if err := client.Initialize(ctx, []string{d.config.TopicName}); err != nil { | ||
return errors.Errorf("could not initialize pubsub client: %w", err) | ||
} | ||
|
||
d.client = client | ||
|
||
sdk.Logger(ctx).Debug(). | ||
Str("at", "destination.open"). | ||
Str("topic", d.config.TopicName). | ||
Msgf("Grpc Client has been set. Will begin read for topic: %s", d.config.TopicName) | ||
|
||
return nil | ||
} | ||
|
||
func (d *Destination) Write(ctx context.Context, rr []opencdc.Record) (int, error) { | ||
for i, r := range rr { | ||
if err := d.client.Write(ctx, r); err != nil { | ||
return i, errors.Errorf("failed to write records: %w", err) | ||
} | ||
} | ||
|
||
return len(rr), nil | ||
} | ||
|
||
func (d *Destination) Teardown(ctx context.Context) error { | ||
if d.client == nil { | ||
return nil | ||
} | ||
|
||
d.client.Stop(ctx) | ||
|
||
if err := d.client.Close(ctx); err != nil { | ||
return errors.Errorf("error when closing subscriber conn: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.