@@ -42,14 +42,8 @@ func (p *processImpl) startConsumingProcess(ctx context.Context) error {
4242 consumer := chainConsumerInterceptors (p .Consumer , p .ConsumerInterceptors ... )
4343
4444 err := p .subscribe (ctx , func (in Message ) {
45- msg := & singleMessage {
46- Ctx : p .createConsumingContext (),
47- Msg : in ,
48- EnqueuedAt : time .Now (),
49- }
50- p .handleMessage (msg , func (in queuedMessage ) error {
51- m := in .(* singleMessage )
52- return errors .WithStack (consumer .Consume (m .Ctx , m .Msg ))
45+ p .handleMessage (p .createConsumingContext (), & singleMessage {Message : in }, func (ctx context.Context ) error {
46+ return errors .WithStack (consumer .Consume (ctx , in ))
5347 })
5448 })
5549 return errors .WithStack (err )
@@ -73,9 +67,9 @@ func (p *processImpl) startBatchConsumingProcess(ctx context.Context) error {
7367 defer p .Logger .Print ("Finish batch consuming process" )
7468
7569 for m := range outCh {
76- p . handleMessage ( m , func ( in queuedMessage ) error {
77- m := in .( * multiMessages )
78- return errors .WithStack (batchConsumer .BatchConsume (m . Ctx , m . Msgs ))
70+ msgs := m . Msgs
71+ p . handleMessage ( m . Ctx , m , func ( ctx context. Context ) error {
72+ return errors .WithStack (batchConsumer .BatchConsume (ctx , msgs ))
7973 })
8074 }
8175 }()
@@ -93,10 +87,11 @@ func (p *processImpl) createConsumingContext() context.Context {
9387 ctx := context .Background ()
9488 ctx = p .StatsHandler .TagProcess (ctx , & BeginTag {})
9589 ctx = p .StatsHandler .TagProcess (ctx , & EnqueueTag {})
90+ ctx = setEnqueuedAt (ctx , time .Now ().UTC ())
9691 return ctx
9792}
9893
99- func (p * processImpl ) handleMessage (m queuedMessage , handle func (queuedMessage ) error ) {
94+ func (p * processImpl ) handleMessage (ctx context. Context , m queuedMessage , handle func (context. Context ) error ) {
10095 p .wg .Add (1 )
10196 go func () {
10297 defer p .wg .Done ()
@@ -107,16 +102,18 @@ func (p *processImpl) handleMessage(m queuedMessage, handle func(queuedMessage)
107102 m .Ack ()
108103 }
109104
110- p .StatsHandler .HandleProcess (m .Context (), & Dequeue {
111- BeginTime : m .GetEnqueuedAt (),
105+ enqueuedAt := getEnqueuedAt (ctx )
106+
107+ p .StatsHandler .HandleProcess (ctx , & Dequeue {
108+ BeginTime : enqueuedAt ,
112109 EndTime : time .Now (),
113110 })
114111
115112 beginTime := time .Now ()
116113
117- m . SetContext ( p .StatsHandler .TagProcess (m . Context () , & ConsumeBeginTag {}) )
114+ ctx = p .StatsHandler .TagProcess (ctx , & ConsumeBeginTag {})
118115
119- err := handle (m )
116+ err := handle (ctx )
120117
121118 if ! p .AckImmediately {
122119 if err != nil {
@@ -126,15 +123,15 @@ func (p *processImpl) handleMessage(m queuedMessage, handle func(queuedMessage)
126123 }
127124 }
128125
129- p .StatsHandler .HandleProcess (m . Context () , & ConsumeEnd {
126+ p .StatsHandler .HandleProcess (ctx , & ConsumeEnd {
130127 BeginTime : beginTime ,
131128 EndTime : time .Now (),
132129 Error : err ,
133130 })
134131
135- p .StatsHandler .HandleProcess (m . Context () , & End {
132+ p .StatsHandler .HandleProcess (ctx , & End {
136133 MsgCount : m .Count (),
137- BeginTime : m . GetEnqueuedAt () ,
134+ BeginTime : enqueuedAt ,
138135 EndTime : time .Now (),
139136 })
140137 }()
0 commit comments