-
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.
- Loading branch information
Showing
6 changed files
with
83 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package linkTrace | ||
|
||
import "github.com/farseer-go/elasticSearch" | ||
|
||
var ESContext *esContext | ||
|
||
// EsContext 链路追踪上下文 | ||
type esContext struct { | ||
TraceContext elasticSearch.IndexSet[TraceContext] `es:"index=linktrace_yyyy_MM;alias=linktrace;shards=1;replicas=0;refresh=3"` | ||
} | ||
|
||
// initEsContext 初始化上下文 | ||
func initEsContext() { | ||
ESContext = elasticSearch.NewContext[esContext]("LinkTrace") | ||
} |
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,26 @@ | ||
package linkTrace | ||
|
||
import ( | ||
"github.com/farseer-go/elasticSearch" | ||
"github.com/farseer-go/fs/modules" | ||
"github.com/farseer-go/queue" | ||
) | ||
|
||
// Enable 是否启用 | ||
var Enable bool | ||
|
||
type Module struct { | ||
} | ||
|
||
func (module Module) DependsModule() []modules.FarseerModule { | ||
return []modules.FarseerModule{queue.Module{}, elasticSearch.Module{}} | ||
} | ||
|
||
func (module Module) PreInitialize() { | ||
Enable = true | ||
} | ||
|
||
func (module Module) PostInitialize() { | ||
initEsContext() | ||
queue.Subscribe("TraceContext", "SaveTraceContext", 1000, saveTraceContextConsumer) | ||
} |
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,14 @@ | ||
package linkTrace | ||
|
||
import ( | ||
"github.com/farseer-go/collections" | ||
"github.com/farseer-go/fs/flog" | ||
"github.com/farseer-go/mapper" | ||
) | ||
|
||
func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListAny, remainingCount int) { | ||
lstTraceContext := mapper.ToList[TraceContext](lstMessage) | ||
err := ESContext.TraceContext.InsertList(lstTraceContext) | ||
_ = flog.Error(err) | ||
return | ||
} |