Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
it512 committed Dec 20, 2024
1 parent de60834 commit a179d67
Show file tree
Hide file tree
Showing 17 changed files with 844 additions and 631 deletions.
11 changes: 11 additions & 0 deletions member/cmd/member/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ package main

import (
"context"
"fmt"
"log"
"net/http"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/twiglab/crm/member/orm"
"github.com/twiglab/crm/member/rpc/gql"
)

const DATABASE_URL = "user=crm password=crm0okm_PL< host=it9i.com port=15432 database=crm sslmode=disable"

func main() {
db, err := orm.FromURL(context.Background(), DATABASE_URL)
if err != nil {
log.Fatal(err)
}

fmt.Println(db.Ping())

mux := chi.NewMux()
mux.Use(middleware.Logger, middleware.Recoverer)
mux.Mount("/rpc", gql.New(context.Background()))
Expand Down
39 changes: 32 additions & 7 deletions member/mq/mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ type RecieverHandler interface {
}

type MemberAuthReciverHandle struct {
RabbitMQ
BindKey string
QueueName string
}

func NewMemberAuthReciverHandle() *MemberAuthReciverHandle {
return &MemberAuthReciverHandle{}
}

func (h *MemberAuthReciverHandle) RecieveDelivery(ctx context.Context, delivery amqp.Delivery) {
Expand All @@ -31,14 +38,9 @@ func (h *MemberAuthReciverHandle) RecieveDelivery(ctx context.Context, delivery
}

type RabbitMQ struct {
Conn *amqp.Connection
channel *amqp.Channel
//队列名称
QueueName string
//交换机名称
Conn *amqp.Connection
channel *amqp.Channel
Exchange string
//bind Key 名称
Key string
}

// 话题模式接受消息
Expand Down Expand Up @@ -121,3 +123,26 @@ func (r *RabbitMQ) Recieve(ctx context.Context, h RecieverHandler) (chan struct{
return forever, nil

}

func (r RabbitMQ) Create() error {
var err error
if r.channel, err = r.Conn.Channel(); err != nil {
return err
}
//1.试探性创建交换机
err = r.channel.ExchangeDeclare(
r.Exchange,
//交换机类型
amqp.ExchangeTopic,
true,
true,
false,
false,
nil,
)
if err != nil {
return err
}

return nil
}
9 changes: 4 additions & 5 deletions member/orm/ent/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 31 additions & 25 deletions member/orm/ent/entql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 38 additions & 30 deletions member/orm/ent/member.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a179d67

Please sign in to comment.