Client constants
const ( ClientVersion = "9.9.9.9.999999.fffff:golang" // Bookmarks BookmarksEPOCH = "0" BookmarksRECENT = "recent" BookmarksNOW = "1|0|" // Acks AckTypeNone = 0 AckTypeReceived = 1 AckTypeParsed = 2 AckTypeProcessed = 4 AckTypePersisted = 8 AckTypeCompleted = 16 AckTypeStats = 32 )
Command Types
const ( CommandAck = iota CommandDeltaPublish CommandDeltaSubscribe CommandFlush CommandGroupBegin CommandGroupEnd CommandOOF CommandPublish CommandSOW CommandSOWAndDeltaSubscribe CommandSOWAndSubscribe CommandSOWDelete CommandSubscribe CommandUnsubscribe CommandUnknown )
AMPS Error constants
const ( // AlreadyConnectedError - Connect() is called while there is already an active connection to AMPS. AlreadyConnectedError = iota // AuthenticationError - returned when the authentication was unsuccessful AuthenticationError // BadFilterError - returned when the AMPS server reports that a filter could not be successfully processed. BadFilterError // BadRegexTopicError - returned when the AMPS server reports that the regex provided as the topic for a // subscription or query could not be processed. This most often indicates a syntax error in the regular expression. BadRegexTopicError // CommandError - returned when an error occurs in an AMPS command. CommandError // ConnectionError - returned when a general connection error occurred. ConnectionError // ConnectionRefusedError - returned when the server is not available or refused to establish the connection. ConnectionRefusedError // DisconnectedError - returned when the client is not connected while attempting to perform an action // that requires a working connection. DisconnectedError // ProtocolError - returned when a general AMPS protocol error occurred. ProtocolError // InvalidTopicError - returned when the AMPS server reports that the command requested is not valid for the topic // specified. InvalidTopicError // InvalidURIError - returned when the provided URI is not valid. InvalidURIError // NotEntitledError - returned when the provided username is not entitled to perform the action. NotEntitledError // RetryOperationError - returned when the attempt to retry to connect to AMPS using an Authenticator has failed. RetryOperationError // SubidInUseError - returned when the specified subscription ID is already in use for this client. SubidInUseError // SubscriptionAlreadyExistsError - returned when a client attempts to register a subscription that already exists. SubscriptionAlreadyExistsError // TimedOutError - returned when the time out occurs before getting the result of an action. TimedOutError // MessageHandlerError - returned when the message hander returned an error after processing the message. MessageHandlerError // UnknownError - when AMPS reports an error of an unknown type, for example, when running an older version of // the AMPS Go client against a more recent version of AMPS. UnknownError )
func NewError(errorCode int, message ...interface{}) error
NewError generates a new AMPS error, with optional description.
The Authenticator interface is used by the client during the logging on. It provides the authentication for custom authentication scenarios when external actions are required before logging on.
Methods:
Authenticate(username string, password string) (string, error)
Authenticate() is called by the Client, just before the logon command is sent. Returns the value that should be placed into the Password header for the logon attempt will be passed, and the error object (nil by default) with information about the error occurred while executing the method.
Retry(username string, password string) (string, error)
Retry() is called when a logon "ack" is received with a status of "retry". AMPS will continue trying to logon as long as the server returns "retry", and this method continues to succeed. Returns the value that should be placed into the Password header for the logon attempt will be passed, and the error object (nil by default) with information about the error occurred while executing the method.
Completed(username string, password string, reason string)
Completed() is called when a logon completes successfully. Once a logon has completed, this method is called with the username and password that caused a successful logon, and optionally, with the reason for this successful completion.
type Authenticator interface { Authenticate(username string, password string) (string, error) Retry(username string, password string) (string, error) Completed(username string, password string, reason string) }
Client struct
type Client struct {
// contains filtered or unexported fields
}
func NewClient(clientName ...string) *Client
NewClient creates a new Client object and returns it.
Arguments:
clientName [string] (optional)
The client name is the optional parameter. Unique name for the client is required (important for queues and sow). It is strongly recommended to set a client name, but if it's not set, it'll be assigned automatically.
func (client *Client) ClientName() string
ClientName is a getter for the client's name. If logon has not been performed yet and the name was not set, returns the empty string.
func (client *Client) Close() error
Close disconnects the client from an AMPS server (if the connection existed).
func (client *Client) Connect(uri string) error
Connect connects the AMPS client to the server using the URI containing all required credentials/addresses/types. After successful connection, the Logon() method must be called, unless the implicit logon is enabled on the server.
func (client *Client) DeltaPublish(topic string, data string, expiration ...uint) error
DeltaPublish delta publishes a message to a SOW topic:
client.DeltaPublish("topic", "{\"id\": 1, \"text\": \"Hello, World\"}");
For regular topics, DeltaPublish() behaves like regular Publish().
Arguments:
topic [string] - The topic to publish data.
data [string] - The data to publish to a topic.
expiration [uint] (optional) - An optional parameter that sets the expiration value on the message (for SOW topics with expiration enabled).
func (client *Client) DeltaPublishBytes(topic string, data []byte, expiration ...uint) error
DeltaPublishBytes is the same as DeltaPublish() but is more optimized for Go's native parsing libraries which almost exclusively utilize slices of bytes ([]byte) as the output format.
func (client *Client) DeltaSubscribe(topic string, filter ...string) (*MessageStream, error)
DeltaSubscribe is the synchronous version of the DeltaSubscribeAsync() method that returns the MessageStream object which can be iterated over in a for loop. Executed in the main thread context.
The delta_subscribe command is like the subscribe command except that subscriptions placed through delta_subscribe will receive only messages that have changed between the SOW record and the new update. If delta_subscribe is used on a record which does not currently exist in the SOW or if it is used on a topic which does not have a SOW-topic store defined, then delta_subscribe behaves like a subscribe command.
Example:
messages, err := client.DeltaSubscribe("orders", "/id > 20") if err != nil { fmt.Println(err); return } for message := messages.Next(); message != nil; message = messages.Next() { fmt.Println("Message Data:", string(message.Data())) }
Arguments:
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) DeltaSubscribeAsync(messageHandler func(*Message) error, topic string, filter ...string) (string, error)
DeltaSubscribeAsync performs the delta_subscribe command. The delta_subscribe command is like the subscribe command except that subscriptions placed through delta_subscribe will receive only messages that have changed between the SOW record and the new update. If delta_subscribe is used on a record which does not currently exist in the SOW or if it is used on a topic which does not have a SOW-topic store defined, then delta_subscribe behaves like a subscribe command.
Example:
subID, err := client.DeltaSubscribeAsync(func(message *amps.Message) error { fmt.Println("Message Data:", string(message.Data())) return nil }, "orders")
Arguments:
messageHandler [func(*Message) error] - The message handler that will be called each time a message is received. Message handler is called from the background thread context.
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) Disconnect() (err error)
Disconnect disconnects the client from an AMPS server (if the connection existed). Same as Close()
func (client *Client) DisconnectHandler() func(*Client, error)
DisconnectHandler gets the disconnect handler that is called in case of an unintentional disconnection.
func (client *Client) ErrorHandler() func(error)
ErrorHandler gets the error handler for all general errors such as connection issues, exceptions, etc.
func (client *Client) Execute(command *Command) (*MessageStream, error)
Execute is the synchronous version of the ExecuteAsync() method which returns the MessageStream object to iterate over in a for loop. Iteration occurs in the main thread context.
Example:
messages, err := client.Execute(amps.NewCommand("sow").SetTopic("orders")) if err != nil { fmt.Println(err); return } for message := messages.Next(); message != nil; message = messages.Next() { fmt.Println("Message Data:", string(message.Data())) }
Arguments:
command [*Command] - the Command object that will be executed, resulting in a MessageStream object.
func (client *Client) ExecuteAsync(command *Command, messageHandler func(message *Message) error) (string, error)
ExecuteAsync is the command execution interface method that allows to send commands that don't have a convenience method or require additional settings that are not provided by the convenience methods. The purpose of the method is to execute Command objects.
Example:
cmdID, err := client.ExecuteAsync(amps.NewCommand("sow").SetTopic("orders"), func(message *amps.Message) error { fmt.Println("Message Data:", string(message.Data())) return nil })
Arguments:
command [*Command] - A command object to execute.
messageHandler [func(*Message) error] (optional) - The message handler that will be called each time a message is received. Message handler is called from the background thread context. If no message handler is needed, provide nil as the second argument.
func (client *Client) Flush() (err error)
Flush ...
func (client *Client) Logon(optionalParams ...LogonParams) (err error)
Logon logs into AMPS with the parameters provided in the connect method, if any, that is set. Optional parameters can be supplied using the LogonParams struct, such as Timeout, Authenticator, and logon CorrelationID.
func (client *Client) LogonCorrelationID() string
LogonCorrelationID gets the uninterpreted logon correlation information a client sends at logon to aid in searching server log files for specific clients. If it was not set, returns the empty string.
func (client *Client) Publish(topic string, data string, expiration ...uint) error
Publish method performs the publish command. The publish command is the primary way to inject messages into the AMPS processing stream. A publish command received by AMPS will be forwarded to other connected clients with matching subscriptions.
Example:
client.Publish("topic", "{\"id\": 1}")
Arguments:
topic [string] - The topic to publish data.
data [string] - The data to publish to a topic.
expiration [uint] (optional) - An optional parameter that sets the expiration value on the message (for SOW topics with expiration enabled).
func (client *Client) PublishBytes(topic string, data []byte, expiration ...uint) error
PublishBytes is the same as Publish() but is more optimized for Go's native parsing libraries which almost exclusively utilize slices of bytes ([]byte) as the output format.
func (client *Client) ServerVersion() string
ServerVersion returns the server version returned by the AMPS server in the logon acknowledgement. If logon has not been performed yet, returns an empty string.
func (client *Client) SetClientName(clientName string) *Client
SetClientName is a setter for the client's name.
func (client *Client) SetDisconnectHandler(disconnectHandler func(*Client, error)) *Client
SetDisconnectHandler sets the disconnect handler that is called in case of an unintentional disconnection.
Example:
client.SetDisconnectHandler(func(cl *amps.Client, err error) { fmt.Println("Switching to the next URI...") connectToNextURI(client); })
func (client *Client) SetErrorHandler(errorHandler func(error)) *Client
SetErrorHandler sets the error handler for all general errors such as connection issues, exceptions, etc.
Example:
client.SetErrorHandler(func(err error) { fmt.Println(time.Now().Local().String() + " [" + client.ClientName() + "] >>>", err) })
func (client *Client) SetHeartbeat(interval uint, providedTimeout ...uint) *Client
SetHeartbeat ...
func (client *Client) SetLogonCorrelationID(logonCorrelationID string) *Client
SetLogonCorrelationID sets the uninterpreted logon correlation information a client sends at logon to aid in searching server log files for specific clients. Can also be set in the LogonParams object supplied to the Logon() method.
func (client *Client) SetTLSConfig(config *tls.Config) *Client
SetTLSConfig is an optional setter for the secure TCP connection configuration parameters, such as Certificates. It must be set before the Connect() and Logon() methods are called. This configuration, is ignored if connecting to a standard non-secure TCP transport.
Example:
client.SetTLSConfig(&tls.Config{ InsecureSkipVerify: true, })
func (client *Client) Sow(topic string, filter ...string) (*MessageStream, error)
Sow is the synchronous version of the SowAsync() method that returns the MessageStream object which can be iterated over in a for loop. Executed in the main thread context.
The sow command is used to query the contents of a previously defined SOW Topic. A sow command can be used to query an entire SOW Topic, or a filter can be used to further refine the results found inside a SOW Topic. For more information, see the State of the World and SOW Queries chapters in the AMPS User Guide.
Example:
messages, err := client.Sow("orders", "/id > 20") if err != nil { fmt.Println(err); return } for message := messages.Next(); message != nil; message = messages.Next() { fmt.Println("Message Data:", string(message.Data())) }
Arguments:
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) SowAndDeltaSubscribe(topic string, filter ...string) (*MessageStream, error)
SowAndDeltaSubscribe is the synchronous version of the SowAndDeltaSubscribeAsync() method that returns the MessageStream object which can be iterated over in a for loop. Executed in the main thread context.
A sow_and_delta_subscribe command is used to combine the functionality of commands sow and a delta_subscribe in a single command. The sow_and_delta_subscribe command is used:
- to query the contents of a SOW topic (this is the sow command); and
- to place a subscription such that any messages matching the subscribed SOW topic and query filter will be published to the AMPS client (this is the delta_subscribe command).
As with the delta_subscribe command, publish messages representing updates to SOW records will contain only the information that has changed. If a sow_and_delta_subscribe is issued on a record that does not currently exist in the SOW topic, or if it is used on a topic that does not have a SOW-topic store defined, then a sow_and_delta_subscribe will behave like a sow_and_subscribe command.
Example:
messages, err := client.SowAndDeltaSubscribe("orders", "/id > 20") if err != nil { fmt.Println(err); return } for message := messages.Next(); message != nil; message = messages.Next() { fmt.Println("Message Data:", string(message.Data())) }
Arguments:
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) SowAndDeltaSubscribeAsync(messageHandler func(*Message) error, topic string, filter ...string) (string, error)
SowAndDeltaSubscribeAsync performs the sow_and_delta_subscribe command. A sow_and_delta_subscribe command is used to combine the functionality of commands sow and a delta_subscribe in a single command. The sow_and_delta_subscribe command is used:
- to query the contents of a SOW topic (this is the sow command); and
- to place a subscription such that any messages matching the subscribed SOW topic and query filter will be published to the AMPS client (this is the delta_subscribe command).
As with the delta_subscribe command, publish messages representing updates to SOW records will contain only the information that has changed. If a sow_and_delta_subscribe is issued on a record that does not currently exist in the SOW topic, or if it is used on a topic that does not have a SOW-topic store defined, then a sow_and_delta_subscribe will behave like a sow_and_subscribe command.
Example:
subID, err := client.SowAndDeltaSubscribeAsync(func(message *amps.Message) error { fmt.Println("Message Data:", string(message.Data())) return nil }, "orders")
Arguments:
messageHandler [func(*Message) error] - The message handler that will be called each time a message is received. Message handler is called from the background thread context.
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) SowAndSubscribe(topic string, filter ...string) (*MessageStream, error)
SowAndSubscribe is the synchronous version of the SowAndSubscribeAsync() method that returns the MessageStream object which can be iterated over in a for loop. Executed in the main thread context.
A sow_and_subscribe command is used to combine the functionality of sow and a subscribe command in a single command. The sow_and_subscribe command is used:
- to query the contents of a SOW topic (this is the sow command); and
- to place a subscription such that any messages matching the subscribed SOW topic and query filter will be published to the AMPS client (this is the subscribe command).
As with the subscribe command, publish messages representing updates to SOW records will contain only information that has changed.
Example:
messages, err := client.SowAndSubscribe("orders", "/id > 20") if err != nil { fmt.Println(err); return } for message := messages.Next(); message != nil; message = messages.Next() { fmt.Println("Message Data:", string(message.Data())) }
Arguments:
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) SowAndSubscribeAsync(messageHandler func(*Message) error, topic string, filter ...string) (string, error)
SowAndSubscribeAsync performs the sow_and_subscribe command. A sow_and_subscribe command is used to combine the functionality of sow and a subscribe command in a single command. The sow_and_subscribe command is used:
- to query the contents of a SOW topic (this is the sow command); and
- to place a subscription such that any messages matching the subscribed SOW topic and query filter will be published to the AMPS client (this is the subscribe command).
As with the subscribe command, publish messages representing updates to SOW records will contain only information that has changed.
Example:
subID, err := client.SowAndSubscribeAsync(func(message *amps.Message) error { fmt.Println("Message Data:", string(message.Data())) return nil }, "orders")
Arguments:
messageHandler [func(*Message) error] - The message handler that will be called each time a message is received. Message handler is called from the background thread context.
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) SowAsync(messageHandler func(*Message) error, topic string, filter ...string) (string, error)
SowAsync performs the sow command. The sow command is used to query the contents of a previously defined SOW Topic. A sow command can be used to query an entire SOW Topic, or a filter can be used to further refine the results found inside a SOW Topic. For more information, see the State of the World and SOW Queries chapters in the AMPS User Guide.
Example:
subID, err := client.SowAsync(func(message *amps.Message) error { fmt.Println("Message Data:", string(message.Data())) return nil }, "orders")
Arguments:
messageHandler [func(*Message) error] - The message handler that will be called each time a message is received. Message handler is called from the background thread context.
topic [string] - The topic argument in SOW.
filter [string] (optional) - An optional content filter value.
func (client *Client) SowDelete(topic string, filter string) (*Message, error)
SowDelete executes a SOW delete with a filter.
Example:
stats, err := client.SowDelete("orders", "1=1") if err != nil { ... } fmt.Println(stats.AckType()) fmt.Println(stats.Status())
Arguments:
topic [string] - The topic to execute the SOW delete against.
filter [string] - The filter. To delete all records, set a filter that is always true: "1 = 1"
Returns the stats message in case of success, error as the second argument otherwise.
func (client *Client) SowDeleteByData(topic string, data []byte) (*Message, error)
SowDeleteByData deletes a message from a SOW, using data supplied to locate a SOW entry with matching keys.
Example:
topic, _ := message.Topic() stats, err := client.SowDeleteByData(topic, message.Data()) if err != nil { ... } fmt.Println(stats.AckType()) fmt.Println(stats.Status())
Arguments:
topic [string] - The topic to execute the SOW delete against.
data [[]byte] - The message data whose keys match the message to be deleted in the server’s SOW.
Returns the stats message in case of success, error as the second argument otherwise.
func (client *Client) SowDeleteByKeys(topic string, keys string) (*Message, error)
SowDeleteByKeys executes a SOW delete with sow keys (supplied as a comma-separated values in a string). SOW keys are provided in the header of a SOW message, and are the internal identifier AMPS uses for that SOW message.
Example:
topic, _ := sowMessage1.Topic() firstMessageKey, _ := sowMessage1.SowKey() secondMessageKey, _ := sowMessage2.SowKey() stats, err := client.SowDeleteByKeys(topic, firstMessageKey + "," + secondMessageKey) if err != nil { ... } fmt.Println(stats.AckType()) fmt.Println(stats.Status())
Arguments:
topic [string] - The topic to execute the SOW delete against.
keys [string] - A comma separated list of SOW keys to be deleted. SOW keys are provided in the header of a SOW message, and are the internal identifier AMPS uses for that SOW message.
Returns the stats message in case of success, error as the second argument otherwise.
func (client *Client) Subscribe(topic string, filter ...string) (*MessageStream, error)
Subscribe is the synchronous version of the SubscribeAsync() method that returns the MessageStream object which can be iterated over in a for loop. Executed in the main thread context.
The subscribe command is the primary way to retrieve messages from the AMPS processing stream. A client can issue a subscribe command on a topic to receive all published messages to that topic in the future. Additionally, content filtering can be used to choose which messages the client is interested in receiving.
Example:
messages, err := client.Subscribe("invoices", "/price > 10000") if err != nil { fmt.Println(err); return } for message := messages.Next(); message != nil; message = messages.Next() { fmt.Println("Message Data:", string(message.Data())) }
Arguments:
topic [string] - The topic argument.
filter [string] (optional) - An optional content filter value.
func (client *Client) SubscribeAsync(messageHandler func(*Message) error, topic string, filter ...string) (string, error)
SubscribeAsync performs the subscribe command. The subscribe command is the primary way to retrieve messages from the AMPS processing stream. A client can issue a subscribe command on a topic to receive all published messages to that topic in the future. Additionally, content filtering can be used to choose which messages the client is interested in receiving.
Example:
subID, err := client.SubscribeAsync(func(message *amps.Message) error { fmt.Println("Message Data:", string(message.Data())) return nil }, "invoices", "/price < 10000")
Arguments:
messageHandler [func(*Message) error] - The message handler that will be called each time a message is received. Message handler is called from the background thread context.
topic [string] - The topic argument.
filter [string] (optional) - An optional content filter value.
func (client *Client) Unsubscribe(subID ...string) error
Unsubscribe performs the unsubscribe command. The unsubscribe command unsubscribes the client from the topic which messages the client is is no more interested in receiving. If the subID is not provided, the client will unsubscribe from all subscriptions.
Arguments:
subID [string] (optional) - The id of the subscription to unsubscribe from. If not provided, the client will unsubscribe from all subscriptions.
Command class encapsulates the AMPS Command entity. The Go client sends Command objects to the server and receives Message objects from the server.
type Command struct {
// contains filtered or unexported fields
}
func NewCommand(commandName string) *Command
NewCommand creates a new Command object and returns it.
Arguments:
commandName [string] - a type of the command to be created. It can be on of the following:
- publish
- delta_publish
- subscribe
- delta_subscribe
- sow
- sow_and_subscribe
- sow_and_delta_subscribe
- sow_delete
- unsubscribe
func (com *Command) AckType() (int, bool)
AckType is the getter for the acknowledgement message type(s) requested by the command. Acknowledgement types can be detected using the bitwise AND and OR operators:
if ackType, _ := command.AckType(); (ackType & amps.AckTypeCompleted) > 0 { ... } // or, to check if there are multiple acks set, the bitwise OR can be used as well: if ackType, _ := command.AckType(); (ackType & (amps.AckTypeProcessed | amps.AckTypeCompleted)) > 0 { ... }
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) AddAckType(ackType int) *Command
AddAckType adds the ack(s) to the list of the acknowledgements requested for the command. Multiple ack types can be combined using bitwise OR:
command.AddAckType(AckTypeProcessed | AckTypeCompleted)
The acknowledgement messages will be delivered to the message handler / message stream.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) BatchSize() (uint, bool)
BatchSize returns the batch size value -- the number of messages that are batched together when returning a query result.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) Bookmark() (string, bool)
Bookmark returns the bookmark value -- the client-originated identifier used to mark a location in journaled messages.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) Command() (string, bool)
Command returns the command type e.g. 'publish', 'sow_and_subscribe', to be executed.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) CommandID() (string, bool)
CommandID returns the Client-specified command id. The command id is returned by the engine in responses to commands to allow the client to correlate the response to the command.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) CorrelationID() (string, bool)
CorrelationID returns the correlation id value, if any.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) Data() []byte
Data returns the Command data (message payload). Only publish, delta_publish, and sow_delete commands can have a payload.
func (com *Command) Expiration() (uint, bool)
Expiration returns the SOW expiration time (in seconds) if used in publish.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) Filter() (string, bool)
Filter returns the content filter expression.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) Options() (string, bool)
Options returns the (comma-delimited) string of options on a specific Command.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) OrderBy() (string, bool)
OrderBy returns the SOW topic key(s) by which to order SOW query.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) QueryID() (string, bool)
QueryID returns the SOW Query identifier set by client to identify a query.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) SequenceID() (uint64, bool)
SequenceID returns the sequence id value. Sequence id is an integer that corresponds to the publish message sequence number. For more information see the Replication section in the User Guide.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) SetAckType(ackType int) *Command
SetAckType sets the acknowledgements requested for the command. Multiple ack types can be combined using bitwise OR:
command.SetAckType(AckTypeProcessed | AckTypeCompleted)
The acknowledgement messages will be delivered to the message handler / message stream.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetBatchSize(batchSize uint) *Command
SetBatchSize sets the number of messages that are batched together when returning a SOW query result. If it's not set, it is 10 by default.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetBookmark(bookmark string) *Command
SetBookmark sets the client-originated identifier used to mark a location in journaled messages.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetCommand(command string) *Command
SetCommand sets the command type e.g. 'publish', 'sow_and_subscribe', to be executed. The following commands are available:
- publish
- delta_publish
- subscribe
- delta_subscribe
- sow
- sow_and_subscribe
- sow_and_delta_subscribe
- sow_delete
- unsubscribe
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetCommandID(commandID string) *Command
SetCommandID sets the Client-specified command id. The command id is returned by the engine in responses to commands to allow the client to correlate the response to the command.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetCorrelationID(correlationID string) *Command
SetCorrelationID sets the opaque token set by an application and returned with the message.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetData(data []byte) *Command
SetData sets the command data (message payload). Makes sense only for publish, delta_publish, and sow_delete commands.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetExpiration(expiration uint) *Command
SetExpiration sets the SOW expiration time (in seconds) if used in publish.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetFilter(filter string) *Command
SetFilter sets the content filter expression.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetOptions(options string) *Command
SetOptions sets the (comma-delimited) string of options on a specific Command.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetOrderBy(orderBy string) *Command
SetOrderBy sets the SOW topic key(s) by which to order SOW query.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetQueryID(queryID string) *Command
SetQueryID sets the SOW Query identifier set by client to identify a query.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetSequenceID(sequenceID uint64) *Command
SetSequenceID sets the sequence id value. Sequence id is an integer that corresponds to the publish message sequence number. For more information see the Replication section in the User Guide.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetSowKey(sowKey string) *Command
SetSowKey sets the sow key value. A SOW key will accompany each message returned in an SOW batch. A SOW key may also be added to messages coming in on a subscription when the published message matches a record in the SOW.
Format:
- string containing the digits of an unsigned long for AMPS-generated SOW keys
OR:
- arbitrary string in the base64 character set for user-provided SOW keys.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetSowKeys(sowKeys string) *Command
SetSowKeys sets the SOW keys as a comma-delimited value.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetSubID(subID string) *Command
SetSubID sets the subscription identifier set by server when processing a subscription.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetSubIDs(subIDs string) *Command
SetSubIDs sets the list of subscription IDs - a comma-separated list of subscription ids sent from AMPS engine to identify which client subscriptions match a given publish message.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SetTopN(topN uint) *Command
SetTopN sets the number of records to return.
Note: If TopN is not equally divisible by the BatchSize value, then more records will be returned so that the total number of records is equally divisible by the BatchSize setting.
Returns the Command object, allowing combining several setters into a chain. Deprecated: Provide the "top_n=<value>" value as a part of the `options` field instead.
func (com *Command) SetTopic(topic string) *Command
SetTopic sets the topic value.
Returns the Command object, allowing combining several setters into a chain.
func (com *Command) SowKey() (string, bool)
SowKey returns the sow key value. A SOW key will accompany each message returned in an SOW batch. A SOW key may also be added to messages coming in on a subscription when the published message matches a record in the SOW.
Format:
- string containing the digits of an unsigned long for AMPS-generated SOW keys
OR:
- arbitrary string in the base64 character set for user-provided SOW keys.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) SowKeys() (string, bool)
SowKeys returns the SOW keys as a comma-delimited value.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) SubID() (string, bool)
SubID returns the subscription identifier set by server when processing a subscription.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) SubIDs() (string, bool)
SubIDs returns the list of subscription IDs - a comma-separated list of subscription ids sent from AMPS engine to identify which client subscriptions match a given publish message.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) TopN() (uint, bool)
TopN returns the number of records to return.
Note: If TopN is not equally divisible by the BatchSize value, then more records will be returned so that the total number of records is equally divisible by the BatchSize setting.
The second returned parameter is set to true if the value exists, false otherwise.
func (com *Command) Topic() (string, bool)
Topic returns the topic value.
The second returned parameter is set to true if the value exists, false otherwise.
CompositeMessageBuilder struct
type CompositeMessageBuilder struct {
// contains filtered or unexported fields
}
func NewCompositeMessageBuilder() *CompositeMessageBuilder
NewCompositeMessageBuilder ...
func (cmb *CompositeMessageBuilder) Append(data string) error
Append appends the given string to the composite message.
Example: json := `{"item":"car","price":20000}` builder := amps.NewCompositeMessageBuilder() builder.Append(json)
client.Publish("test", builder.GetData())
Arguments: data [string] - The string to append to the composite message
func (cmb *CompositeMessageBuilder) AppendBytes(data []byte, offset int, length int) error
AppendBytes appends the given byte buffer to the composite message.
Example: bin := []byte{0, 1, 2} builder := amps.NewCompositeMessageBuilder() builder.AppendBytes(bin, 0, 3)
client.Publish("test", builder.GetData())
Arguments: data [byte buffer] - The bytes to append to the composite message offset [int] - Location in the buffer where the bytes to append begin length [int] - Length of the buffer
func (cmb *CompositeMessageBuilder) Clear()
Clear clears the message object.
func (cmb *CompositeMessageBuilder) GetBytes() []byte
GetBytes returns the composite message's data, as a byte array.
Example:
bin := []byte{0, 1, 2} builder := amps.NewCompositeMessageBuilder() builder.AppendBytes(bin, 0, 3)
client.Publish("test", builder.GetBytes())
func (cmb *CompositeMessageBuilder) GetData() string
GetData returns the composte message's data, as a string. Use this when you want to publish a composite message.
Example: json := `{"item":"car","price":20000}` builder := amps.NewCompositeMessageBuilder() builder.Append(json)
client.Publish("test", builder.GetData())
CompositeMessageParser struct
type CompositeMessageParser struct {
// contains filtered or unexported fields
}
func NewCompositeMessageParser() *CompositeMessageParser
NewCompositeMessageParser ...
func (cmp *CompositeMessageParser) Parse(data []byte) (int, error)
Parse parses a composite AMPS.Message, returns the number of valid parts parsed.
Example: _, err = client.SubscribeAsync(func(message *amps.Message) (msgError error) {
parser := amps.NewCompositeMessageParser() parts, _ := parser.ParseMessage(message) for i := 0; i < int(parts); i++ { part, _ := parser.Part(i) fmt.Println("part", i, string(part)) }
}
Arguments: data [byte buffer] - Byte buffer containing the data to be parsed
func (cmp *CompositeMessageParser) ParseMessage(message *Message) (int, error)
ParseMessage parses a composite AMPS.Message, returns the data from the composite message.
Example: _, err = client.SubscribeAsync(func(message *amps.Message) (msgError error) {
parser := amps.NewCompositeMessageParser() parts, _ := parser.ParseMessage(message) for i := 0; i < int(parts); i++ { part, _ := parser.Part(i) fmt.Println("part", i, string(part)) }
}
Arguments: message [*Message] - Message object to parse
func (cmp *CompositeMessageParser) Part(index int) ([]byte, error)
Part returns the index'th part of the composite message. If the index provided is greater than the size of the part, or if the index is negative, return an "Invalid parts index" error.
Example: _, err = client.SubscribeAsync(func(message *amps.Message) (msgError error) {
parser := amps.NewCompositeMessageParser() parts, _ := parser.ParseMessage(message) for i := 0; i < int(parts); i++ { part, _ := parser.Part(i) fmt.Println("part", i, string(part)) }
}
Arguments: index [int] - The index used to locate a part of the composite message
func (cmp *CompositeMessageParser) Size() int
Size returns the size of the part parsed from the composite message.
FixMessageBuilder struct
type FixMessageBuilder struct {
// contains filtered or unexported fields
}
func NewFIXBuilder(fieldSep ...byte) *FixMessageBuilder
NewFIXBuilder use this method to create a new FIX message.
Example: builder := amps.NewFIXBuilder()
Arguments: fieldSep [byte] (optional) - The default is \x01, a different one can be provided
func (fmb *FixMessageBuilder) Append(tag int, value string) error
Append appends teh given tag (int) and the value (string) to the FIX message.
Example: value := "This is a value" builder := amps.NewFIXBuilder() builder.Append(1, value)
client.Publish("fix-topic", builder.Data())
Arguments: tag [int] - The int to be the key in the FIX message value [string] - The string to be the value in the FIX message
Returns: Illegal argument error - If the provided tag is negative
func (fmb *FixMessageBuilder) AppendBytes(tag int, value []byte, offset int, length int) error
AppendBytes appends the given tag (integer) and value (byte array) to the FIX message.
Example: value := "This is the value" builder := amps.NewFIXMessageBuilder() builder.AppendBytes(1, []byte(value), 0, len(value))
client.Publish("test-topic", builder.Data())
Arguments: tag [int] - The integer to be the key in the FIX message value [byte buffer] - The bytes to be the value in the FIX message offset [int] - Location in the buffer where the bytes to append begin length [int] - Length of the value in the buffer
Returns: Illegal argument error - If the provided tag is negative
func (fmb *FixMessageBuilder) Bytes() []byte
Bytes returns the FIX message, in the form of a byte buffer
func (fmb *FixMessageBuilder) Clear()
Clear clears the FIX message
func (fmb *FixMessageBuilder) Data() string
Data returns the FIX message, in the form of a string
func (fmb *FixMessageBuilder) Size() int
Size returns the size of the FIX message
FixMessageShredder struct
type FixMessageShredder struct {
// contains filtered or unexported fields
}
func NewFIXShredder(fieldSep ...byte) *FixMessageShredder
NewFIXShredder use this method to parse a FIX message.
Example: shredder := amps.NewFIXShredder()
Arguments: fieldSep [byte] (optional) - The default is \x01, a different one can be provided
func (fms *FixMessageShredder) ToMap(fix []byte) map[int]string
ToMap use this method to parse a FIX message.
Example: shredder := amps.NewFIXShredder()
sow, _ := client.Sow("fix-topic") for sow.HasNext() {
message := sow.Next() fields := shredder.ToMap(message.Data()) for key, value := range fields { fmt.Println("key:", key, "value:", value) }
}
Arguments: fix [byte buffer] - The byte buffer containing the FIX message to be parsed
Returns: map - A map with integer keys and string values
LogonParams is the struct that can be supplied to the Logon() method of the Client in order to supply an Authenticator object and/or a timeout value and Correlation id. If Timeout is not set or set to 0, there will be no timeout for Logon().
Parameters:
Authenticator [Authenticator] (optional) - The custom Authenticator object to authenticate against.
Timeout [uint] (optional) - The number of milliseconds to wait for AMPS to acknowledge the command, where 0 indicates no timeout.
CorrelationID [string] (optional) - the uninterpreted logon correlation information a client sends at logon to aid in searching server log files for specific clients.
type LogonParams struct { Timeout uint Authenticator Authenticator CorrelationID string }
Message is the AMPS message representation class. Any message received from AMPS is a Message object. Messages have two main components: header and data. Most header properties can be accessed via getters, such as command type, message length, sow key, etc. Message payload can be accessed using the Data() getter method.
Note: Not all messages populate all headers. The Command Reference provides detailed description of the headers returned on specific messages and what they contain
type Message struct {
// contains filtered or unexported fields
}
func (msg *Message) AckType() (int, bool)
AckType is the getter for the acknowledgement type of the message. Acknowledgement type can be one of the following:
- amps.AckTypeNone (for all non-ACK messages)
- amps.AckTypeReceived
- amps.AckTypeParsed
- amps.AckTypeProcessed
- amps.AckTypePersisted
- amps.AckTypeCompleted
- amps.AckTypeStats
Example:
if ackType, _ := message.AckType(); ackType == amps.AckTypeCompleted { ... }
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) BatchSize() (uint, bool)
BatchSize returns the batch size value -- the number of messages that are batched together when returning a query result.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Bookmark() (string, bool)
Bookmark returns the bookmark value -- the client-originated identifier used to mark a location in journaled messages.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Command() (int, bool)
Command returns the type e.g. amps.CommandPublish, amps.CommandSOW, of the message. Can be one of the following:
- amps.CommandAck
- amps.CommandGroupBegin
- amps.CommandGroupEnd
- amps.CommandOOF
- amps.CommandPublish
- amps.CommandSOW
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) CommandID() (string, bool)
CommandID returns the Client-specified id. The command id is returned by the engine in responses to commands to allow the client to correlate the response to the command.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Copy() *Message
Copy creates a deep copy of the Message object. Most common use case is to keep a copy of the message delivered to a message handler by one of the async client methods, such as ExecuteAsync(), since these methods reuse the same Message object in order to be GC-friendly.
func (msg *Message) CorrelationID() (string, bool)
CorrelationID returns the correlation id value, if any.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Data() []byte
Data returns the Message data (payload). Only amps.CommandPublish, amps.CommandSOW, and amps.CommandOOF messages can have a payload.
func (msg *Message) Expiration() (uint, bool)
Expiration returns the SOW expiration time (in seconds) if used in publish.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Filter() (string, bool)
Filter returns the content filter expression.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) GroupSequenceNumber() (uint, bool)
GroupSequenceNumber returns the Group Sequence Number for each batch message of a SOW response.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) LeasePeriod() (string, bool)
LeasePeriod -- for messages from a queue, returns the time at which the lease expires.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Matches() (uint, bool)
Matches returns the number of matches as a part of the acknowledgement to a SOW query.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) MessageLength() (uint, bool)
MessageLength is sent to indicate the number of bytes used by the message body.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Options() (string, bool)
Options returns a comma-delimited list of options on a specific command.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) OrderBy() (string, bool)
OrderBy returns the SOW topic key(s) by which to order SOW query.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) QueryID() (string, bool)
QueryID returns the SOW Query identifier set by client to identify a query.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Reason() (string, bool)
Reason returns the failure message that appears when an acknowledgement returns a status of failure.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) RecordsDeleted() (uint, bool)
RecordsDeleted returns the number of records deleted from the SOW with a sow_delete command. Used in conjunction with the stats acknowledgement message.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) RecordsInserted() (uint, bool)
RecordsInserted returns the number of records inserted into the SOW. Used in conjunction with the stats acknowledgement message.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) RecordsReturned() (uint, bool)
RecordsReturned returns number of records in the store. The value is returned in the acknowledgement to an SOW query.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) RecordsUpdated() (uint, bool)
RecordsUpdated returns the number of records updated in the SOW. Used in conjunction with the stats acknowledgement message.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) SequenceID() (uint64, bool)
SequenceID returns an integer that corresponds to the publish message sequence number. For more information see the Replication section in the User Guide.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) SowKey() (string, bool)
SowKey returns the sow key value. A SOW key will accompany each message returned in an SOW batch. A SOW key may also be added to messages coming in on a subscription when the published message matches a record in the SOW.
Format:
- string containing the digits of an unsigned long for AMPS-generated SOW keys
OR:
- arbitrary string in the base64 character set for user-provided SOW keys.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) SowKeys() (string, bool)
SowKeys returns the SOW keys as a comma-delimited value.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Status() (string, bool)
Status returns the client status when client is monitored for heartbeats.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) SubID() (string, bool)
SubID returns the subscription identifier set by server when processing a subscription.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) SubIDs() (string, bool)
SubIDs returns the list of subscription IDs - a comma-separated list of subscription ids sent from AMPS engine to identify which client subscriptions match a given publish message.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Timestamp() (string, bool)
Timestamp returns the message timestamp set by the server in a ISO-8601 date-time format.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) TopN() (uint, bool)
TopN returns the number of records to return.
Note: If TopN is not equally divisible by the BatchSize value, then more records will be returned so that the total number of records is equally divisible by the BatchSize setting.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) Topic() (string, bool)
Topic returns the topic value.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) TopicMatches() (uint, bool)
TopicMatches returns the number of topic matches for the SOW query. Sent in stats acknowledgement message.
The second returned parameter is set to true if the value exists, false otherwise.
func (msg *Message) UserID() (string, bool)
UserID returns the user id used to identify the user of a command.
The second returned parameter is set to true if the value exists, false otherwise.
MessageRoute struct
type MessageRoute struct {
// contains filtered or unexported fields
}
MessageRouter struct
type MessageRouter struct { MessageRoute // contains filtered or unexported fields }
func (msgRouter *MessageRouter) AddRoute( commandID string, messageHandler func(*Message) error, requestedAcks int, systemAcks int, isSubscribe bool, isReplace bool, )
AddRoute ...
func (msgRouter *MessageRouter) Clear()
Clear ...
func (msgRouter *MessageRouter) DeliverAck(ackMessage *Message, ackType int) int
DeliverAck ...
func (msgRouter *MessageRouter) DeliverData(dataMessage *Message) int
DeliverData ...
func (msgRouter *MessageRouter) DeliverDataWithID(dataMessage *Message, cmdID string) int
DeliverDataWithID ...
func (msgRouter *MessageRouter) FindRoute(commandID string) func(*Message) error
FindRoute ...
func (msgRouter *MessageRouter) RemoveRoute(commandID string)
RemoveRoute ...
func (msgRouter *MessageRouter) UnsubscribeAll()
UnsubscribeAll ...
MessageStream provides an iteration abstraction over the results of an AMPS command such as a subscribe, a SOW query, or SOW delete. MessageStream is produced when calling Client.Execute() and continues iterating over the results until the connection is closed, or the iterator is explicitly closed, or when the SOW query is ended. You can use a MessageStream as you would other iterators, for example, using a for loop:
messages, err := client.Sow("orders", "/id > 20") if err != nil { fmt.Println(err); return } for message := messages.Next(); message != nil; message = messages.Next() { fmt.Println("Message Data:", string(message.Data())) }
All sync methods of the Client (such as Sow(), Subscribe(), SowAndSubscribe(), etc) return a MessageStream object.
type MessageStream struct {
// contains filtered or unexported fields
}
func (ms *MessageStream) Close() (err error)
Close -- closes this MessageStream, unsubscribing from AMPS if applicable.
Returns an error object if an error occurred while closing the stream.
func (ms *MessageStream) Conflate()
Conflate ...
func (ms *MessageStream) Depth() uint64
Depth returns the current amount of messages in the queue to iterate over.
func (ms *MessageStream) HasNext() bool
HasNext is called to verify that there are more messages in the MessageStream. Returns true if there are more messages in the MessageStream and false if the MessageStream is empty.
Example: messages, err := client.Execute(amps.NewCommand("subscribe").SetTopic("test-topic")) if err != nil { fmt.Println(err); return }
for messages.HasNext() {
message := messages.Next() fmt.Println("Message Data:", string(message.Data()))
}
func (ms *MessageStream) MaxDepth() uint64
MaxDepth returns the maximum size of the message stream queue. Once the maximum depth is reached, the message stream blocks and stops accepting new messages, until the queue is drained below the MaxDepth value (if any).
Returns 0 by default, which means no maximum depth is set. In this case the stream will keep adding messages to the queue until all the available RAM is consumed.
func (ms *MessageStream) Next() (message *Message)
Next is called to get the next message in the stream. It only returns nil if there are no more messages in the stream (for example, for SOW queries after delivering the group_end message).
func (ms *MessageStream) SetMaxDepth(depth uint64) *MessageStream
SetMaxDepth sets the maximum depth of the message stream. Once the maximum depth is reached, the message stream blocks and stops accepting new messages, until the queue is drained below the MaxDepth value (if any).
If set to 0 it means no maximum depth is set. In this case the stream will keep adding messages to the queue until all the available RAM is consumed.
func (ms *MessageStream) SetTimeout(timeout uint64) *MessageStream
SetTimeout sets a timeout on self. If no message is received in this timeout, Next() returns nil, but leaves the stream open.
Arguments:
timeout [uint64] - The timeout in milliseconds, or 0 for infinite timeout.
Returns the MessageStream object, allowing combining several setters into a chain.
func (ms *MessageStream) Timeout() uint64
Timeout returns the timeout value in milliseconds, if any. If returns 0 then no timeout is set (by default).
NvfixMessageBuilder struct
type NvfixMessageBuilder struct {
// contains filtered or unexported fields
}
func NewNVFIXBuilder(fieldSep ...byte) *NvfixMessageBuilder
NewNVFIXBuilder use this method to create a new NVFIX message.
Example: builder := amps.NewNVFIXBuilder()
Arguments: fieldSep [byte] (optional) - The default is \x01, a different one can be provided
func (nmb *NvfixMessageBuilder) AppendBytes(tag []byte, value []byte, valOffset int, valLength int) error
AppendBytes appends the given tag (byte array) and the value (byte array) to the NVFIX message.
Example: value := "Here is the value" builder := amps.NewNVFIXBuilder() builder.AppendBytes([]byte("key"), []byte(value), 0, len(value))
client.Publish("nvfix-topic", builder.Data())
Arguments: tag [byte buffer] - The byte buffer to be the key in the NVFIX message value [byte buffer] - The bytes to be the value in the NVFIX message valOffset [int] - The location in the buffer where the bytes to append begin (for the value) valLength [int] - The length of the value in the buffer
Returns: Illegal Argument error - If the provided tag is empty
func (nmb *NvfixMessageBuilder) AppendStrings(tag string, value string) error
AppendStrings appends the given tag (string) and the value (string) to the NVFIX message.
Example: value := "This is a value" key := "This is the key" builder := amps.NewNVFIXBuilder() builder.AppendStrings(key, value)
client.Publish("nvfix-topic", builder.Data())
Arguments: tag [string] - The string to be the key in the NVFIX message value [string] - The string to be the key in the NVFIX message
Returns: Illegal Argument error - If the provided tag is empty
func (nmb *NvfixMessageBuilder) Bytes() []byte
Bytes returns the NVFIX message, in the form of a byte buffer
func (nmb *NvfixMessageBuilder) Clear()
Clear clears the NVFIX message
func (nmb *NvfixMessageBuilder) Data() string
Data returns the NVFIX message, in the form of a string
func (nmb *NvfixMessageBuilder) Size() int
Size returns the size of the NVFIX message
NvfixMessageShredder struct
type NvfixMessageShredder struct {
// contains filtered or unexported fields
}
func NewNVFIXShredder(fieldSep ...byte) *NvfixMessageShredder
NewNVFIXShredder use this method to parse a FIX message.
Example: shredder := amps.NewNVFIXShredder()
Arguments: fieldSep [byte] (optional) - The default is \x01, a different one can be provided
func (nfs *NvfixMessageShredder) ToMap(nvfix []byte) map[string]string
ToMap use this method to parse a NVFIX message.
Example: shredder := amps.NewNVFIXShredder()
sow, _ := client.Sow("nvfix-topic") for sow.HasNext() {
message := sow.Next() fields := shredder.ToMap(message.Data()) for key, value := range fields { fmt.Println("key:", key, "value:", value) }
}
Arguments: nvfix [byte buffer] - The byte buffer containing the NVFIX message to be parsed
Returns: map - A map with string keys and string values