Message Provider Development

Messages that will be pushed to each Nexacro Client are transmitted through the X-PUSH Server and socket communication. The protocol to be used for communication is defined when messages are provided, and an API is provided for Java.

Message Composition

The messages pushed by X-PUSH Server are comprised of the following three items:

The Topic Type is a sort of group that indicates the message type. You can categorize the types for each message such as current share price, operation data, news, etc.

The Topic ID distinguishes the messages within one Topic Type. Messages can be distinguished by the stock code for each stock even for the same current share price data.

The Topic Type and the Topic ID form a single Topic Key. Topics with the same ID may be different if they use different topic types. For example, a message composed of the "current share price" as the Topic Type and stock code "1001" as the Topic ID has a different Topic Key from a message composed with "recent news" as the Topic Type and stock code "1001" as the Topic ID.

Field Values are the content to be actually delivered.

English letters, numbers, and special characters (- _ @ .) can be used for Topic Id.

Message Size Restrictions

The maximum size of the message being transmitted is 999,999 bytes, able to be expressed with a message length of 6 bytes. Since all X-PUSH operations are handled in individual message units, however, large message sizes can significantly impact the performance, and memory shortages may occur.

The recommended sizes for X-PUSH are as follows:

As Field Values contain separators, the actual data is less than 4000byte.

Java API

The library for using the Java API is xpush-x.x.x_API.jar located in the $XPUSH_HOME/api path.

An API for pushing messages is provided for Java, so separate development is not necessary for actual socket communication. Three classes are provided in the API:

PushMessageProvider

void connect(String host, int port, String id, String password)

Create connection.

PushResponse sendPushMessage(PushMessage pushMessage)

Transmit PushMessage.

void close()

Terminate connection.

PushMessageBinaryProvider

void connect(String host, int port, String id, String password)

Create connection

PushResponse sendPushMessage(PushMessage pushMessage)

Send PushMessage

void close()

Terminate connection

void useKeepService(boolean f)

Set whether to use keep

void setKeepIntervalTime(long time)

Set keep time interval

PushMessage

void setProjectID(String projectID)

Set projectID

void setTopicType(String topicType)

Set Topic Type

void setTopicId(String topicId)

Set Topic Id

void setActionType(String Action)

Set action

void addData(String data)

Add data

void addData(byte[] data)

Add data

void addData(int index, String data)

Add data

void addData(int index, byte[] data)

Add data

void setData(int index, String data)

Edit data

void setData(int index, byte[] data)

Edit data

void resetData()

Edit data

void removeData()

Delete data

void removeData(int index)

Delete data

void setAvailablePeriod(long days)

Message storage period

void setEmergencyMessage(boolean emergency)

Set emergency message

List Unmarshal(String data)

Convert data

PushMessageProvider

Establish a connection with the X-PUSH server and transmit a message using the Json protocol.

The connect() and close() methods for creating connections and sendMessage() method for actual message transmission are provided.

Package

com.nexacro.xpush.api

connect

Method for connecting to an X-PUSH Server and authenticating.

void connect (String host, int port, String id, String password) throws UnknownHostException, IOException, LoginFailException, ConnectionClosedException;
void connect (String host, int port, String id, String password, boolean useResponse) throws UnknownHostException, IOException, LoginFailException, ConnectionClosedException

Parameters - connect (String host, int port, String id, String password)

host

IP address of the X-PUSH Server to be connected.

port

Message Provider connection port for the X-PUSH Server to be connected.

id

User authentication ID

password

User authentication password

Parameters - connect (String host, int port, String id, String password, boolean useResponse)

host

연결하고자 하는 X-PUSH 서버의 IP 주소

port

연결하고자 하는 X-PUSH 서버의 Message Provider 접속 포트

id

사용자 인증 id

password

사용자 인증 password

useResponse

response 수신 여부, ActionType 이 Constants.ACTION_PUSH_STRING 일 시 적용

Exception

UnknownHostException

Occurs when the X-PUSH Server’s address value (host, port) is invalid.

IOException

Occurs for network communication errors.

LoginFailException

Occurs when user authentication fails.

ConnectionClosedException

Occurs when a connection is not possible because the respective channel is terminated.

sendPushMessage

One PushMessage object is sent to an X-PUSH Server.

PushResponse sendPushMessage (PushMessage pushMessage) throws IOException

Parameters

pushMessage

Object containing the push message data to be transmitted to an X-PUSH Server.

Return value

PushResponse

Provider response object

The PushResponse object is returned when the ActionType is Constants.ACTION_RELI_STRING or Constants.ACTION_MONT_STRING.


Method

getAction() : Message action

getBodysize() : Message body size

isSucceed() : Success or fail (true or false)

getErrorCode() : Success or fail (OK or NG)

getSessionId() : Session ID

response.getBody() : Byte message

getMessage() : Error message

Exception

IOException

Occurs for network communication errors.

close

Close is a method to disconnect from the X-PUSH Server that was connected by using the PushMessageProvider.connect() method. It's generally called when terminating message communication with an X-PUSH Server.

void close () throws IOException

Exception

IOException

Occurs for network communication errors.

PushMessageBinaryProvider

Establish a connection with the X-PUSH server and transmit a message using the Binary protocol.

Provides the connect() and close() methods for connection and the sendMessage() method for actual message transmission.

Provides the useKeepService() method to set whether to use provider keep and the setKeepIntervalTime() method to set the provider keep time interval.

Package

com.nexacro.xpush.api

connect

This is a method to connect to the X-PUSH server and authenticate.

void connect (String host, int port, String id, String password) throws UnknownHostException, IOException, LoginFailException, ProtocolMismatchException;

Parameters

host

IP address of the X-PUSH server you want to connect to

port

Message Provider connection port of the X-PUSH server you want to connect to

id

User authentication id

password

User authentication password

Exception

UnknownHostException

This occurs when the address value (host, port) of the X-PUSH server you want to connect to is incorrect.

IOException

Occurs when a network communication error occurs.

LoginFailException

Occurs when user authentication fails.

ConnectionClosedException

This occurs when connection is not possible due to the channel being terminated or other reasons.

sendPushMessage

Send one PushMessage object to the X-PUSH server.

PushResponse sendPushMessage (PushMessage pushMessage) throws IOException

Parameters

pushMessage

Object that stores the Push Message data to be transmitted to the X-PUSH server

Return value

PushResponse

provider response object

When ActionType is Constants.ACTION_RELI_STRING or Constants.ACTION_MONT_STRING, a PushResponse object is returned.


method

getAction() : Message Action

getBodysize() : Message body size

isSucceed(): Success, failure (true, false)

getErrorCode() : Success, failure ("OK" or "NG")

getSessionId() : Session ID

response.getBody() : Byte message

getMessage() : Error message

Exception

IOException

Occurs when a network communication error occurs.

close

This is the method that disconnects the connection from the X-PUSH server created using the PushMessageProvider.connect() method. This method called when the message communication with the X-PUSH server is terminated.

void close () throws IOException

Exception

IOException

Occurs when a network communication error occurs.

useKeepService

This is a method to set whether to use Provider Keep.

void useKeepService (boolean f)

Parameters

f

Boolean value that sets whether to use Provider Keep (default = false)

The corresponding method needs to be called before performing the connection

setKeepIntervalTime

This method sets the Provider Keep time interval.

void setKeepIntervalTime (long time)

Parameters

time

Long value that sets the Provider Keep time interval (unit: ms)

The corresponding method needs to be called before performing the connection

setKeepErrorCallBack

Register callback function

void setKeepErrorCallBack(KeepErrorCallBack callback)

Parameters

callback

CallBack Interface


ex)

// Create callback

KeepErrorCallBack keepErrorCallBack = new KeepErrorCallBack() {


// User-defined function

public void onData(String remoteSession, String localSession) {

/*

* remoteSession:59.10.169.3:50002, localSession:172.10.12.24:48429

*/

System.out.println("onData() " + remoteSession + ", " + localSession);

}

};


// Apply callback function

pushMessageBinaryProvider.setKeepErrorCallBack(keepErrorCallBack);

The corresponding method needs to be called before performing the connection

PushMessage

Class that corresponds to the message for transmission to an X-PUSH Server. One message consists of the Topic Type, Topic ID, and data. The Topic Type is a sort of group or type for messages, and the Topic ID is a delimiter for distinguishing each message. The data is the actual message to be transmitted.

Package

nexacro.xpush.fw.service.provider

setProjectID

Set the ProjectID value.

void setProjectID (String projectID)

Parameters

projectID

projectID value to set.

setTopicType

Set the Topic Type value.

void setTopicType (String TopicType)

Parameters

TopicType

Topic type value for configuring.

The type is set according to the message characteristics. For example, current share price can be set to "CPDT," operation data can be set to "OPDT," and news can be to "NEWS." The types can be defined accordingly to fit the system.


The topic type must be 4 bytes.

setTopicId

Set the Topic ID. Set the key for selecting a message from a particular type of messages. For example, the topicId is "1234" for messages transmitting share prices with the stock code "1234" among "CPDT" type current share price messages.

void setTopicId(String topicId)

Parameters

TopicType

Topic type value for configuring.

setActionType

Method for adding values to be transmitted.

void setActionType(String actionType)

Parameters

actionType

Action type to be configured.

Reliability message: Constants.ACTION_RELI_STRING

Real-time message: Constants.ACTION_PUSH_STRING

addData

Method for adding values to be transmitted.

void addData (String data)

Parameters

value

String value to be transmitted.

void addData (byte[] data)

Parameters

data

Byte[] value to deliver

void addData (int index, String data)

Parameters

index

index

data

String value to be delivered to the corresponding index

void addData (int index, byte[] data)

Parameters

index

index

data

Byte[] value to be delivered to the corresponding index

setData

This is a method that modifies the value to be delivered.

void setData (int index, String data)

Parameters

index

index

data

String value to be delivered to the corresponding index

void setData (int index, byte[] data)

Parameters

index

index

data

Byte[] value to be delivered to the corresponding index

resetData

This method deletes the value to be delivered.

void resetData ()

removeData

This method deletes the value to be delivered.

void removeData ()
void removeData (int index)

Parameters

index

index

setAvailablePeriod

Available Period of Reliable Message

void setAvailablePeriod(int days)

Parameters

days

Unit in days

setEmergencyMessage

Emergency Message

- If set to true, the priority of the message is the highest as soon as it is sent and is loaded as the first in each queue. This allows you to receive client or mobile Notification first.

void setEmergencyMessage(boolean emergency)

Parameters

emergency

true / false

unmarshal

Data Conversion

- message_body data of the T_Message table is returned in List<String> type.

List<String> unmarshal(String value)

Parameters

value

message_body column value of T_Message table

ex) 0020004Test0005Test1

Example

Json protocol example

General message

public class DemoProvider_Push {
	public static void main(String[] args) {

		String host = "localhost";
		int port = 50002;
		String id = "tobesoft";
		String password = "xpush";

		System.out.println("host="+host+", 
			port="+port+", 
			id="+id+", 
			password="+password);

		PushMessageProvider pushMessageProvider 
			= new PushMessageProvider();
		try {
			pushMessageProvider.connect(host, port, id, password);
		} catch (UnknownHostException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (LoginFailException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (ConnectionClosedException e) {
			e.printStackTrace();
			System.exit(0);
		}

		try {
			PushMessage pushMessageNOTI = new PushMessage();
			pushMessageNOTI.setActionType(Constants.ACTION_PUSH_STRING);
			pushMessageNOTI.setCharsetName("utf-8");
			pushMessageNOTI.setProjectID("PRO#1");
			pushMessageNOTI.setTopicType("NOTI");
			pushMessageNOTI.setTopicId("000000001");
			pushMessageNOTI.addData("Tobesoft Push Message " + currentTime);
            PushResponse response = 
                     pushMessageProvider.sendPushMessage(pushMessageNOTI);

	System.out.println("response.isSucceed() : " + response.isSucceed());
	System.out.println("response.getErrorCode() : " + response.getErrorCode());
    System.out.println("response.getResponseMessage().getMessageId() : "
     + response.getResponseMessage().getMessageId());
	System.out.println("response.getResponseMessage().getTopic().getType() : "
     + response.getResponseMessage().getTopic().getType());
	System.out.println("response.getResponseMessage().getTopic().getId() : "
     + response.getResponseMessage().getTopic().getId());

		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (XPushMessageException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} 

		try {
			pushMessageProvider.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Reliability Message

public class DemoProvider_Reli {
	public static void main(String[] args) {

		String host = "localhost";
		int port = 50002;
		String id = "tobesoft";
		String password = "xpush";

		System.out.println("host="+host+", 
			port="+port+", 
			id="+id+", 
			password="+password);
		PushMessageProvider pushMessageProvider = new PushMessageProvider();
		try {
			pushMessageProvider.connect(host, port, id, password);
		} catch (UnknownHostException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (LoginFailException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (ConnectionClosedException e) {
			e.printStackTrace();
			System.exit(0);
		}

		try {
			PushMessage pushMessageOPDT = new PushMessage();
			pushMessageOPDT.setActionType(Constants.ACTION_RELI_STRING);
			pushMessageOPDT.setCharsetName("utf-8");
            pushMessageOPDT.setProjectID("PRO#1");
			pushMessageOPDT.setTopicType("OPDT");
			pushMessageOPDT.setTopicId("ALL");
			SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
			String currentTime = "pushed current time : "+
				formatter.format(new Date());
			pushMessageOPDT.addData(currentTime);
            pushMessageOPDT.setAvailablePeriod(30);
			PushResponse response = 
				pushMessageProvider.sendPushMessage(pushMessageOPDT);
            System.out.println( "isSuccess(true or false) : " 
                           + response.isSucceed() );
            System.out.println("MessageId :" 
                           + response.getResponseMessage().getMessageId()); 
            System.out.println("TopicType :" 
                           + response.getResponseMessage().getTopic().getType() ); 
            System.out.println("TopicId : " 
                           + response.getResponseMessage().getTopic().getId() ); 
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Exception e="+e);
		} catch (XPushMessageException e) {
			e.printStackTrace();
		}

		try {
			pushMessageProvider.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Binary protocol example

General message

public class PushMessageBinaryProvider_Push {
	public static void main(String[] args) {				
		PushMessageBinaryProvider pushMessageBinaryProvider = new PushMessageBinaryProvider();		
		try {			
			/*
			 * Whether to use Keep service or not
			 */		
			pushMessageBinaryProvider.useKeepService(false);
			pushMessageBinaryProvider.setKeepIntervalTime(1 * 1000); // default: 5000
			KeepErrorCallBack keepErrorCallBack = new KeepErrorCallBack() {
				public void onData(String remoteSession, String localSession) {
					/*
					 * remoteSession:59.10.169.3:50002, localSession:172.10.12.24:48429
					 */
					System.out.println("onData() remoteSession:" + remoteSession + ", localSession:" + localSession);
				}
			};
			pushMessageBinaryProvider.setKeepErrorCallBack(keepErrorCallBack);		

				
			pushMessageBinaryProvider.connect("localhost",50002,"tobesoft","xpush");
			
			PushMessage pushMessage = new PushMessage();
			pushMessage.setProjectID("TFT");
			pushMessage.setTopicType("NOTI");
			pushMessage.setTopicId("ALL");						
			pushMessage.setActionType(Constants.ACTION_PUSH_STRING); // General message
					
			/*
			 * Add (String)
			 */
			pushMessage.addData("11111");	
			pushMessage.addData("22222");
			pushMessage.addData("33333");
			
			/*
			 * Add (byte[])
			 */
			pushMessage.addData("aaa");
			pushMessage.addData("bbb".getBytes());			
			
			/*
			 * Add (String to the corresponding index)
			 */
			pushMessage.addData(0, "ccc");
			
			/*
			 * Add (byte[] to the corresponding index)
			 */			
			pushMessage.addData(2, "ddd".getBytes());			
						
			/*
			 * Edit (String to the corresponding index)
			 */
			pushMessage.setData(1, "eee");
			
			/*
			 * Edit (byte[] to the corresponding index)
			 */
			pushMessage.setData(2, "fff".getBytes());
			
			/*
			 * Delete
			 */
//			pushMessage.resetData();	
//			pushMessage.removeData();		
			
			/*
			 * Delete (value of the corresponding index)
			 */
			pushMessage.removeData(1);			
			
				
			PushResponse pushResponse = pushMessageBinaryProvider.sendPushMessage(pushMessage);
			System.out.println("pushResponse = " + pushResponse);
			if(pushMessage.getActionType().equals("RELI")) {
				System.out.println("isSucceed: " + pushResponse.isSucceed());
				if(!pushResponse.getErrorCode().equals("OK")) {
					System.out.println("ErrorCode: "+pushResponse.getErrorCode());
				}
				System.out.println("Action(): " + pushResponse.getAction());
				System.out.println("ProjectID(): " + pushResponse.getProjectID());
				System.out.println("SessionId(): " + pushResponse.getSessionId());
				System.out.println("MessageId(): " + pushResponse.getResponseMessage().getMessageId());
				System.out.println("Type(): " + pushResponse.getResponseMessage().getTopic().getType());
				System.out.println("Id(): " + pushResponse.getResponseMessage().getTopic().getId());			
			}			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LoginFailException e) {
			e.printStackTrace();
		} catch (ConnectionClosedException e) {
			e.printStackTrace();
		} catch (RuntimeException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} 		
		
		try {
			pushMessageBinaryProvider.close();
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
}

Reliability message

public class PushMessageBinaryProvider_Push {
	public static void main(String[] args) {				
		PushMessageBinaryProvider pushMessageBinaryProvider = new PushMessageBinaryProvider();		
		try {			
			/*
			 * Whether to use Keep service or not
			 */		
			pushMessageBinaryProvider.useKeepService(false);
			pushMessageBinaryProvider.setKeepIntervalTime(1 * 1000); // default: 5000
			KeepErrorCallBack keepErrorCallBack = new KeepErrorCallBack() {
				public void onData(String remoteSession, String localSession) {
					/*
					 * remoteSession:59.10.169.3:50002, localSession:172.10.12.24:48429
					 */
					System.out.println("onData() remoteSession:" + remoteSession + ", localSession:" + localSession);
				}
			};
			pushMessageBinaryProvider.setKeepErrorCallBack(keepErrorCallBack);		

				
			pushMessageBinaryProvider.connect("localhost",50002,"tobesoft","xpush");
			
			PushMessage pushMessage = new PushMessage();
			pushMessage.setProjectID("TFT");
			pushMessage.setTopicType("NOTI");
			pushMessage.setTopicId("ALL");						
			pushMessage.setActionType(Constants.ACTION_RELI_STRING); // Reliability message
					
			/*
			 * Add (String)
			 */
			pushMessage.addData("11111");	
			pushMessage.addData("22222");
			pushMessage.addData("33333");
			
			/*
			 * Add (byte[])
			 */
			pushMessage.addData("aaa");
			pushMessage.addData("bbb".getBytes());			
			
			/*
			 * Add (String to the corresponding index)
			 */
			pushMessage.addData(0, "ccc");
			
			/*
			 * Add (byte[] to the corresponding index)
			 */			
			pushMessage.addData(2, "ddd".getBytes());			
						
			/*
			 * Edit (String to the corresponding index)
			 */
			pushMessage.setData(1, "eee");
			
			/*
			 * Edit (byte[] to the corresponding index)
			 */
			pushMessage.setData(2, "fff".getBytes());
			
			/*
			 * Delete
			 */
//			pushMessage.resetData();	
//			pushMessage.removeData();		
			
			/*
			 * Delete (value of the corresponding index)
			 */
			pushMessage.removeData(1);			
			
				
			PushResponse pushResponse = pushMessageBinaryProvider.sendPushMessage(pushMessage);
			System.out.println("pushResponse = " + pushResponse);
			if(pushMessage.getActionType().equals("RELI")) {
				System.out.println("isSucceed: " + pushResponse.isSucceed());
				if(!pushResponse.getErrorCode().equals("OK")) {
					System.out.println("ErrorCode: "+pushResponse.getErrorCode());
				}
				System.out.println("Action(): " + pushResponse.getAction());
				System.out.println("ProjectID(): " + pushResponse.getProjectID());
				System.out.println("SessionId(): " + pushResponse.getSessionId());
				System.out.println("MessageId(): " + pushResponse.getResponseMessage().getMessageId());
				System.out.println("Type(): " + pushResponse.getResponseMessage().getTopic().getType());
				System.out.println("Id(): " + pushResponse.getResponseMessage().getTopic().getId());			
			}			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LoginFailException e) {
			e.printStackTrace();
		} catch (ConnectionClosedException e) {
			e.printStackTrace();
		} catch (RuntimeException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} 		
		
		try {
			pushMessageBinaryProvider.close();
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
}