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.

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

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

PushMessageProvider

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

Create connection.

void sendPushMessage(PushMessage pushMessage)

Transmit PushMessage.

void close()

Terminate connection.

PushMessage

void setProjectID(String projectID)

projectID setting

void setActionType(String Action)

Set action.

void setTopicType(String topicType)

Set TopicType.

void setTopicId(String topicId)

Set Topic ID.

void addData(String value)

Add data.

void setAvailablePeriod(long days)

Message storage period

void setEmergencyMessage(boolean emergency)

Emergency message setting

List<String> unmarshal(String value)

Data conversion

PushMessageProvider

Create a connection with the X-PUSH Server and transmit messages.

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

Package

com.nexacro.xpush.api

setUseProject

Method to set whether to use the project ID

public void setUseProject(boolean useProject)

Parameters

userProject

Whether to use the project ID

The default value is true

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, ProtocolMismatchException;

Parameters

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

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.

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

TopicID

The topic id value to set.

Only English language letters and standard numerals are available for TopicID.

addData

Method for adding values to be transmitted.

void addData (String value)

Parameters

value

Value to be transmitted.

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

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

General message

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

		String host = "localhost";
		int port = 10082;
		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 = 10082;
		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();
		}
	}
}