mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-16 13:04:34 +00:00
Moving cruftier services that are only used for tests under a test repo
This commit is contained in:
24
test/pubsub/README.md
Normal file
24
test/pubsub/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# PubSub
|
||||
|
||||
A simple example of using PubSub
|
||||
|
||||
## Overview
|
||||
|
||||
This example is a simple pubsub service which subscribes to a topic and periodically publishes
|
||||
to the same place. The interface for how it works may change but its simple enough.
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
# start micro
|
||||
micro server
|
||||
|
||||
# run pubsub
|
||||
micro run pubsub
|
||||
|
||||
# check status
|
||||
micro status
|
||||
|
||||
# get the logs
|
||||
micro logs pubsub
|
||||
```
|
||||
50
test/pubsub/main.go
Normal file
50
test/pubsub/main.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/micro/micro/v3/service"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
pb "github.com/micro/services/pubsub/proto"
|
||||
)
|
||||
|
||||
// Pub will publish messages every second
|
||||
func Pub() {
|
||||
ev := service.NewEvent("messages")
|
||||
|
||||
for {
|
||||
err := ev.Publish(context.TODO(), &pb.Message{
|
||||
Id: "1",
|
||||
Body: []byte(`hello`),
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("Error Publish:", err.Error())
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
// Sub processes messages
|
||||
func Sub(ctx context.Context, msg *pb.Message) error {
|
||||
fmt.Println("Received a message")
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
service := service.New(
|
||||
service.Name("pubsub"),
|
||||
)
|
||||
|
||||
// subscribe to the "messages" topic
|
||||
service.Subscribe("messages", Sub)
|
||||
|
||||
// publish messages
|
||||
go Pub()
|
||||
|
||||
if err := service.Run(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
157
test/pubsub/proto/pubsub.pb.go
Normal file
157
test/pubsub/proto/pubsub.pb.go
Normal file
@@ -0,0 +1,157 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.25.0
|
||||
// protoc v3.11.4
|
||||
// source: github.com/micro/services/pubsub/proto/pubsub.proto
|
||||
|
||||
package pubsub
|
||||
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
type Message struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Message) Reset() {
|
||||
*x = Message{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_github_com_micro_services_pubsub_proto_pubsub_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Message) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Message) ProtoMessage() {}
|
||||
|
||||
func (x *Message) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_github_com_micro_services_pubsub_proto_pubsub_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Message.ProtoReflect.Descriptor instead.
|
||||
func (*Message) Descriptor() ([]byte, []int) {
|
||||
return file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Message) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Message) GetBody() []byte {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_github_com_micro_services_pubsub_proto_pubsub_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDesc = []byte{
|
||||
0x0a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x69, 0x63,
|
||||
0x72, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x70, 0x75, 0x62, 0x73,
|
||||
0x75, 0x62, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x75, 0x62, 0x73, 0x75, 0x62, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x70, 0x75, 0x62, 0x73, 0x75, 0x62, 0x22, 0x2d, 0x0a,
|
||||
0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescOnce sync.Once
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescData = file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescGZIP() []byte {
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescOnce.Do(func() {
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescData)
|
||||
})
|
||||
return file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_github_com_micro_services_pubsub_proto_pubsub_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_github_com_micro_services_pubsub_proto_pubsub_proto_goTypes = []interface{}{
|
||||
(*Message)(nil), // 0: pubsub.Message
|
||||
}
|
||||
var file_github_com_micro_services_pubsub_proto_pubsub_proto_depIdxs = []int32{
|
||||
0, // [0:0] is the sub-list for method output_type
|
||||
0, // [0:0] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_github_com_micro_services_pubsub_proto_pubsub_proto_init() }
|
||||
func file_github_com_micro_services_pubsub_proto_pubsub_proto_init() {
|
||||
if File_github_com_micro_services_pubsub_proto_pubsub_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Message); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_github_com_micro_services_pubsub_proto_pubsub_proto_goTypes,
|
||||
DependencyIndexes: file_github_com_micro_services_pubsub_proto_pubsub_proto_depIdxs,
|
||||
MessageInfos: file_github_com_micro_services_pubsub_proto_pubsub_proto_msgTypes,
|
||||
}.Build()
|
||||
File_github_com_micro_services_pubsub_proto_pubsub_proto = out.File
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_rawDesc = nil
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_goTypes = nil
|
||||
file_github_com_micro_services_pubsub_proto_pubsub_proto_depIdxs = nil
|
||||
}
|
||||
21
test/pubsub/proto/pubsub.pb.micro.go
Normal file
21
test/pubsub/proto/pubsub.pb.micro.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: github.com/micro/services/pubsub/proto/pubsub.proto
|
||||
|
||||
package pubsub
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
8
test/pubsub/proto/pubsub.proto
Normal file
8
test/pubsub/proto/pubsub.proto
Normal file
@@ -0,0 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package pubsub;
|
||||
|
||||
message Message {
|
||||
string id = 1;
|
||||
bytes body = 2;
|
||||
}
|
||||
Reference in New Issue
Block a user