Comments (7)
I agree that we need to pass the context.Context
somehow up to the ProcessCallback
. Otherwise one needs to hack it via closure.
Another problem of extending the goka.Context
interface is that it conflicts with the context.Context()
in the Value()
method.
Do you think that returning the context with ctx.Context()
or ctx.Background()
would be an alternative? Too confusing? Otherwise we'd need to rename the Value()
method.
from goka.
You're right about the conflict in the method name! If backward compatibility is not an issue, Value
could be renamed. Although I think we could do something similar to what net/http
did for Request
:
- Add
Context
method togoka.Context
. Calling this method would returncontext.Context
passed to the processor'sRun
method. - Add
WithContext
method togoka.Context
. It would acceptcontext.Context
and would return shallow copy ofgoka.Context
. Like that: https://godoc.org/net/http#Request.WithContext This is useful for creating child context off of processor's context. For example to add some trace id for a particular message or stuff like this.
I think this kind of change would be the least destructive.
from goka.
I forgot to mention that step 0 would be to insert processor's context.Context
inside goka.Context
, that further would be available with Context()
method on goka.Context
.
from goka.
Steps 0 and 1 are very easy, I can quickly build them. But I am not very sure how one would use the WithContext
method. Can you give an example?
Looking forward, after closing this ticket with a non-destructive solution, I'd suggest we start discussing how the callback interface could be redesigned. We can plan an API breaking release if we pack enough changes together, for example, #108.
from goka.
WithContext
could be useful if you isolate the logic in some sort of Service struct or separate function.
For example I commonly implement the handling in some sort of service type, and then wrap it inside DefineGroup
call.
Here is a rough example:
func NewProcessor(brokers []string, svc *FooService, opts ...goka.ProcessorOption) {
goka.DefineGroup("group", goka.Input("topic1", new(myCodec), func(ctx goka.Context, message interface{}) {
// Here is when we could derive context if needed...
stdctx := addTracingInformationOrAnythingElse(ctx.Context())
ctx = ctx.WithContext(stdctx)
if err := svc.HandleFooMessage(ctx, message.(*FooMessage)); err != nil {
// Sometimes not all errors should trigger panic, so we can handle this specific errors in one place here if needed.
// ...
ctx.Fail(err)
}
}))
}
type FooService struct {
Log Logger
DB Database
Client SomeHTTPClient
// ...
}
type FooMessage struct {
FieldOne string
FieldTwo string
// ...
}
func (fs *FooService) HandleFooMessage(ctx goka.Context, message *FooMessage) error {
// Here is where one could use the underlying context.
fs.Client.Do(ctx.Context(), "rest of parameters here")
// Handle specific type of *FooMessage.
// Don't use ctx.Fail here, and instead return normal error.
// This is more portable and easier to test if needed to test only the logic.
return nil
}
from goka.
Totally agree on that. We could group enough breaking changes before doing them.
Looking forward, after closing this ticket with a non-destructive solution, I'd suggest we start discussing how the callback interface could be redesigned. We can plan an API breaking release if we pack enough changes together, for example, #108.
from goka.
Let's close this and have another discussion if the issue comes up again.
from goka.
Related Issues (20)
- Pause and Resume Functionality in Processor HOT 4
- Link to blog post is dead HOT 1
- Processor calls wrong decode codec on message receipt HOT 1
- Any way allow to customize key of KTable HOT 1
- bug error setting up for partition HOT 3
- how to use Goka to move data from group table state to different storage system HOT 4
- EmitSync stuck in channel HOT 3
- Cannot connect to broker if the program is on docker container HOT 3
- Kafka server: Message was too large, server rejected it to avoid allocation error HOT 3
- How to modify value in Group table? HOT 4
- What storage I should use for processor and view? HOT 4
- How to fill up local cache with messages from a custom offset on start up? HOT 1
- Convert to using github.com/IBM/sarama HOT 1
- [question] Azure EventHub HOT 1
- no automatic reconnection processor ? HOT 1
- LevelDB - No space left on device HOT 1
- "panic: sync: negative WaitGroup counter" in PartitionProcessor.VisitValues HOT 8
- Behavior of View Sync HOT 1
- Configuring Sarama's initial offset to OffsetOldest leads the existing group to reprocess topic messages from start HOT 3
- Writing to group table from asynchronous function; using ctx.SetValue causes a WaitGroup panic
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goka.