georgehao commented on code in PR #803:
URL: https://github.com/apache/rocketmq-client-go/pull/803#discussion_r851024099


##########
internal/request_response_future.go:
##########
@@ -0,0 +1,135 @@
+package internal
+
+import (
+       "context"
+       "fmt"
+       "sync"
+       "time"
+
+       "github.com/patrickmn/go-cache"
+       "github.com/pkg/errors"
+
+       "github.com/apache/rocketmq-client-go/v2/primitive"
+       "github.com/apache/rocketmq-client-go/v2/rlog"
+)
+
+var RequestResponseFutureMap = NewRequestResponseFutureMap()
+
+type requestResponseFutureCache struct {
+       cache *cache.Cache
+}
+
+func NewRequestResponseFutureMap() *requestResponseFutureCache {
+       tmpRrfCache := requestResponseFutureCache{
+               cache: cache.New(5*time.Minute, 10*time.Minute),
+       }
+
+       // OnEvicted delete the timeout RequestResponseFuture, trigger set the 
failure cause.
+       tmpRrfCache.cache.OnEvicted(func(s string, i interface{}) {
+               rrf, ok := i.(*RequestResponseFuture)
+               if !ok {
+                       rlog.Error("convert i to RequestResponseFuture err", 
map[string]interface{}{
+                               "correlationId": s,
+                       })
+                       return
+               }
+               if !rrf.IsTimeout() {
+                       return
+               }
+
+               err := fmt.Errorf("correlationId:%s request timeout, no reply 
message", s)
+               rrf.CauseErr = err
+               rrf.ExecuteRequestCallback()

Review Comment:
   > 的异步回调,同步超时问题
   
   有处理呀,这个貌似没有问题。
   
   > Automatically delete cache when it times out If there are exceptions and 
timeouts, do you want to delete them from the cache
   >
   > cache 超时时候自动删除 如果异常与超时,是否要从cache中删除
   使用的是开源的 gocache 组件,这个组件会自动处理这个事情。
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to