-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed pkg/cloudevents/transport/x to pkg/binding (#181)
Main types are binding.Message, binding.Sender and binding.Receiver which reads well in code, corresponds to CE spec use of the term "binding", and avoids clashes with existing package name "transport". Part of #180 - The AMQP transport will be re-factored to use this package. Signed-off-by: Alan Conway <aconway@redhat.com>
- Loading branch information
1 parent
a1c7a75
commit d3eb0a1
Showing
6 changed files
with
106 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Package binding is for implementing transport bindings and | ||
intermediaries like importers, brokers or channels that forward | ||
messages between bindings. | ||
A transport binding implements Message, Sender and Receiver interfaces. | ||
An intermediary uses those interfaces to transfer event messages. | ||
A Message is an abstract container for an Event. It provides | ||
additional methods for efficient forwarding of structured events | ||
and reliable delivery when the underlying transports support it. | ||
A Receiver can return instances of its own Message implementations. A | ||
Sender must be able to send any implementation of the Message | ||
interface, but it may provide optimized handling for its own Message | ||
implementations. | ||
For transports that support a reliable delivery QoS, the Message | ||
interface allows acknowledgment between sender and receiver for QoS | ||
level 0, 1 or 2. The effective QoS is the lowest provided by sender or | ||
receiver. | ||
*/ | ||
package binding |
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
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,52 @@ | ||
package binding | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cloudevents/sdk-go/pkg/cloudevents" | ||
"github.com/cloudevents/sdk-go/pkg/cloudevents/transport" | ||
) | ||
|
||
// Transport implements the transport.Transport interface using a | ||
// Sender and Receiver. | ||
type Transport struct { | ||
Sender Sender | ||
Receiver Receiver | ||
handler transport.Receiver | ||
} | ||
|
||
var _ transport.Transport = (*Transport)(nil) // Test it conforms to the interface | ||
|
||
func NewTransport(s Sender, r Receiver) *Transport { | ||
return &Transport{Sender: s, Receiver: r} | ||
} | ||
|
||
func (t *Transport) Send(ctx context.Context, e cloudevents.Event) (context.Context, *cloudevents.Event, error) { | ||
return ctx, nil, t.Sender.Send(ctx, EventMessage(e)) | ||
} | ||
|
||
func (t *Transport) SetReceiver(r transport.Receiver) { t.handler = r } | ||
|
||
func (t *Transport) StartReceiver(ctx context.Context) error { | ||
for { | ||
if m, err := t.Receiver.Receive(ctx); err != nil { | ||
return err | ||
} else if e, err := m.Event(); err != nil { | ||
m.Finish(err) | ||
return err | ||
} else if err := t.handler.Receive(ctx, e, nil); err != nil { | ||
m.Finish(err) | ||
return err | ||
} else { | ||
m.Finish(nil) | ||
} | ||
} | ||
} | ||
|
||
func (t *Transport) SetConverter(transport.Converter) { | ||
// TODO(alanconway) Can we separate Converter from the base transport interface? | ||
} | ||
|
||
func (t *Transport) HasConverter() bool { | ||
return false | ||
} |
This file was deleted.
Oops, something went wrong.