-
Notifications
You must be signed in to change notification settings - Fork 427
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
11 changed files
with
180 additions
and
67 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
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,52 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/apache/rocketmq-client-go/v2" | ||
"github.com/apache/rocketmq-client-go/v2/primitive" | ||
"github.com/apache/rocketmq-client-go/v2/producer" | ||
) | ||
|
||
func main() { | ||
p, _ := rocketmq.NewProducer( | ||
producer.WithGroupName("please_rename_unique_group_name"), | ||
producer.WithNsResolver(primitive.NewPassthroughResolver([]string{"127.0.0.1:9876"})), | ||
producer.WithRetry(2), | ||
) | ||
err := p.Start() | ||
if err != nil { | ||
fmt.Printf("start producer error: %s", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
topic := "RequestTopic" | ||
ttl := 5 * time.Second | ||
msg := &primitive.Message{ | ||
Topic: topic, | ||
Body: []byte("Hello RPC RocketMQ Go Client!"), | ||
} | ||
|
||
now := time.Now() | ||
f := func(ctx context.Context, responseMsg *primitive.Message, respErr error) { | ||
if respErr != nil { | ||
fmt.Printf("request to <%s> fail, err:%v \n", topic, respErr) | ||
return | ||
} | ||
fmt.Printf("Requst to %s cost:%d ms responseMsg:%s\n", topic, time.Since(now).Milliseconds(), responseMsg.String()) | ||
} | ||
err = p.RequestAsync(context.Background(), ttl, f, msg) | ||
if err != nil { | ||
fmt.Printf("Request Async message error: %s\n", err) | ||
return | ||
} | ||
|
||
time.Sleep(time.Minute) | ||
err = p.Shutdown() | ||
if err != nil { | ||
fmt.Printf("shutdown producer error: %s", err.Error()) | ||
} | ||
} |
File renamed without changes.
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,39 @@ | ||
package internal | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/apache/rocketmq-client-go/v2/primitive" | ||
) | ||
|
||
// CreateReplyMessage build reply message from the request message | ||
func CreateReplyMessage(requestMessage *primitive.MessageExt, body []byte) (*primitive.Message, error) { | ||
if requestMessage == nil { | ||
return nil, errors.New("create reply message fail, requestMessage cannot be null") | ||
} | ||
|
||
cluster := requestMessage.GetProperty(primitive.PropertyCluster) | ||
replyTo := requestMessage.GetProperty(primitive.PropertyMessageReplyToClient) | ||
correlationId := requestMessage.GetProperty(primitive.PropertyCorrelationID) | ||
ttl := requestMessage.GetProperty(primitive.PropertyMessageTTL) | ||
|
||
if cluster == "" { | ||
return nil, fmt.Errorf("create reply message fail, requestMessage error, property[\"%s\"] is null", cluster) | ||
} | ||
|
||
var replayMessage primitive.Message | ||
|
||
replayMessage.UnmarshalProperties(body) | ||
replayMessage.Topic = GetReplyTopic(cluster) | ||
replayMessage.WithProperty(primitive.PropertyMsgType, ReplyMessageFlag) | ||
replayMessage.WithProperty(primitive.PropertyCorrelationID, correlationId) | ||
replayMessage.WithProperty(primitive.PropertyMessageReplyToClient, replyTo) | ||
replayMessage.WithProperty(primitive.PropertyMessageTTL, ttl) | ||
|
||
return &replayMessage, nil | ||
} | ||
|
||
func GetReplyToClient(msg *primitive.MessageExt) string { | ||
return msg.GetProperty(primitive.PropertyMessageReplyToClient) | ||
} |
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 was deleted.
Oops, something went wrong.
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