###kafka
Broker 集群包含了一个或者多个服务器
Topic 每条发布到kafka几群的消息都有一个类别,这个类别称为Topic
Partation 物理概念,每个topic包含一个或者多个Partation
Producer 负责发布消息到kafka broker
consumer 订阅模式 subscribe() assign()
commit实现 commitAsync() commitSync()
// 订阅指定的 topic 列表,并且会自动进行动态 partition 订阅
// 当发生以下情况时,会进行 rebalance: 1.订阅的 topic 列表改变; 2.topic 被创建或删除; 3.consumer 线程 die; 4. 加一个新的 consumer 线程
// 当发生 rebalance 时,会唤醒 ConsumerRebalanceListener 线程
public void subscribe(Collection
// 同上,但是这里没有设置 listener
public void subscribe(Collection
//note: 订阅那些满足一定规则(pattern)的 topic
public void subscribe(Pattern pattern, ConsumerRebalanceListener listener){}
go中异常处理 defer,panic,recover
抛出一个panic异常,然后再defer中通过recover捕获这个异常
int8 1byte
uint8 1byte
int16 2
uint16 2
int32 4
uint32 4
int64 8
uint64 8
go中的new func new(Type) *Type 分配一个Type类型的指针
make func make(Type,size IntegerType)Type 返回引用 初始化一个slice/map/chan对象,并非指针
make和new的区别 make用于内建类型(map,slice,channel)的内存分配 new用于各种类型的内存分配
path/filepath func Abs(path string) (string,error)
Abs返回path代表的绝对路径
io
func ReadAtLeast(r Reader,buf []byte,min int)(n int,err error)
从r中读取至少min字节数填充进buf,函数返回写入的字节数和错误
(没有读取到字节时返回EOF)(读取字节数未达到min时返回ErrUnexceptedEOF)(min的长度比buf长时,返回ErrShortBuffer )
go中可以返回局部变量的地址,但是C不可以 C里面会造成内存访问越界,因为局部变量的地址可能进行了重新分配
===========go中的打印================
fmt.Printf,fmt.Fprintf,fmt.Sprintf 返回一个字符串
fmt.Printf(“Hello %d\n”, 23) //这个不会自己换行
fmt.Fprint(os.Stdout, “Hello “, 23, “\n”)
fmt.Println(“Hello”, 23)
fmt.Println(fmt.Sprint(“Hello “, 23))
打印结构体时 %v %+v 会为结构体的每个字段加上字段名 %#v go的语法打印方式
type T struct {
a int
b float64
c string
}
t := &T{ 7, -2.35, “abc\tdef” }
fmt.Printf(“%v\n”, t)
fmt.Printf(“%+v\n”, t)
fmt.Printf(“%#v\n”, t)
fmt.Printf(“%#v\n”, timeZone)
&{7 -2.35 abc def}
&{a:7 b:-2.35 c:abc def}
&main.T{a:7, b:-2.35, c:”abc\tdef”}
map[string] int{“CST”:-21600, “PST”:-28800, “EST”:-18000, “UTC”:0, “MST”:-25200}
%T 打印值的类型 fmt.Printf(“%T\n”,T)
2019/2/15——— 一个傻子的学习
1 package main
2
3 import (
4 "fmt"
5 "reflect"
6 )
7
8 var x = 3
9
10 func main() {
11 fmt.Println(“x type:”, reflect.TypeOf(x), x, &x)
12 x = 4 //这个是局部变量覆盖全局变量
13 fmt.Println(“x type:”, reflect.TypeOf(x), x, &x)
14 x := 5.55 //这个是重新定义
15 fmt.Println(“x type:”, reflect.TypeOf(x), x, &x)
16 }
输出结果如下
x type: int 3 0x4f6018
x type: int 4 0x4f6018
x type: float64 5.55 0xc42000e288