@@ -139,7 +139,7 @@ func (c *Client) peerProperties() error {
139139 writeString (b , element )
140140 }
141141
142- return c .handleWrite (b .Bytes (), resp )
142+ return c .handleWrite (b .Bytes (), resp ). Err
143143}
144144
145145func (c * Client ) authenticate (user string , password string ) error {
@@ -193,14 +193,14 @@ func (c *Client) sendSaslAuthenticate(saslMechanism string, challengeResponse []
193193 writeInt (b , len (challengeResponse ))
194194 b .Write (challengeResponse )
195195 err := c .handleWrite (b .Bytes (), resp )
196- if err != nil {
197- return err
196+ if err . Err != nil {
197+ return err . Err
198198 }
199199 // double read for TUNE
200200 tuneData := <- respTune .data
201- err = c .coordinator .RemoveResponseByName ("tune" )
202- if err != nil {
203- return err
201+ errR : = c .coordinator .RemoveResponseByName ("tune" )
202+ if errR != nil {
203+ return errR
204204 }
205205
206206 return c .socket .writeAndFlush (tuneData .([]byte ))
@@ -214,7 +214,18 @@ func (c *Client) open(virtualHost string) error {
214214 writeProtocolHeader (b , length , commandOpen ,
215215 correlationId )
216216 writeString (b , virtualHost )
217- return c .handleWrite (b .Bytes (), resp )
217+ err := c .handleWriteWithResponse (b .Bytes (), resp , false )
218+ if err .Err != nil {
219+ return err .Err
220+ }
221+
222+ advHostPort := <- resp .data
223+ for k , v := range advHostPort .(ClientProperties ).items {
224+ c .clientProperties .items [k ] = v
225+ }
226+ _ = c .coordinator .RemoveResponseById (resp .correlationid )
227+ return nil
228+
218229}
219230
220231func (c * Client ) DeleteStream (streamName string ) error {
@@ -227,7 +238,7 @@ func (c *Client) DeleteStream(streamName string) error {
227238
228239 writeString (b , streamName )
229240
230- return c .handleWrite (b .Bytes (), resp )
241+ return c .handleWrite (b .Bytes (), resp ). Err
231242}
232243
233244func (c * Client ) heartBeat () {
@@ -330,7 +341,7 @@ func (c *Client) DeclarePublisher(streamName string, channelConfirmListener Publ
330341 writeShort (b , int16 (publisherReferenceSize ))
331342 writeString (b , streamName )
332343 res := c .handleWrite (b .Bytes (), resp )
333- return producer , res
344+ return producer , res . Err
334345}
335346
336347func (c * Client ) metaData (streams ... string ) * StreamsMetadata {
@@ -353,7 +364,7 @@ func (c *Client) metaData(streams ...string) *StreamsMetadata {
353364 }
354365
355366 err := c .handleWrite (b .Bytes (), resp )
356- if err != nil {
367+ if err . Err != nil {
357368 return nil
358369 }
359370
@@ -369,7 +380,7 @@ func (c *Client) BrokerLeader(stream string) (*Broker, error) {
369380
370381 streamMetadata := streamsMetadata .Get (stream )
371382 if streamMetadata .responseCode != responseCodeOk {
372- return nil , fmt . Errorf ( "leader error for stream: %s, error:%s" , stream , lookErrorCode (streamMetadata .responseCode ) )
383+ return nil , lookErrorCode (streamMetadata .responseCode )
373384 }
374385 return streamMetadata .Leader , nil
375386}
@@ -405,7 +416,7 @@ func (c *Client) DeclareStream(streamName string, options *StreamOptions) error
405416 writeString (b , element )
406417 }
407418
408- return c .handleWrite (b .Bytes (), resp )
419+ return c .handleWrite (b .Bytes (), resp ). Err
409420
410421}
411422
@@ -438,6 +449,12 @@ func (c *Client) DeclareSubscriber(ctx context.Context, streamName string,
438449 // here we change the type since typeLastConsumed is not part of the protocol
439450 options .Offset .typeOfs = typeOffset
440451 }
452+
453+ // copy the option offset to the consumer offset
454+ // the option.offset won't change ( in case we need to retrive the original configuration)
455+ // consumer.current offset will be moved when reading
456+ consumer .setCurrentOffset (options .Offset .offset )
457+
441458 resp := c .coordinator .NewResponse (commandSubscribe , streamName )
442459 correlationId := resp .correlationid
443460 var b = bytes .NewBuffer (make ([]byte , 0 , length + 4 ))
@@ -467,7 +484,7 @@ func (c *Client) DeclareSubscriber(ctx context.Context, streamName string,
467484 }
468485
469486 case data := <- consumer .response .data :
470- consumer .setOffset (data .(int64 ))
487+ consumer .setCurrentOffset (data .(int64 ))
471488
472489 case messages := <- consumer .response .messages :
473490 for _ , message := range messages {
@@ -476,5 +493,5 @@ func (c *Client) DeclareSubscriber(ctx context.Context, streamName string,
476493 }
477494 }
478495 }()
479- return consumer , err
496+ return consumer , err . Err
480497}
0 commit comments