본문 바로가기
기획자

GCM 구글문서 번역(3) - Send-to-Sync vs. Messages with Payload

by garyston 2012. 7. 24.

Send-to-Sync vs. Messages with Payload


Every message sent in GCM has the following characteristics:

· It has a payload limit of 4096 bytes.

· By default, it is stored by GCM for 4 weeks.

→ GCM을 사용한 모든 메시지는 기본적인 특성으로 Payload 메시지를 4096 Byte를 쓸 수 있고 기본적으로 GCM에 4주간 저장되어 있습니다.

But despite these similarities, messages can behave very differently depending on their particular settings. One major distinction between messages is whether they are collapsed (where each new message replaces the preceding message) or not collapsed (where each individual message is delivered). Every message sent in GCM is either a "send-to-sync" (collapsible) message or a "message with payload" (non-collapsible message). These concepts are described in more detail in the following sections.

→ 그러나, 메시지들은 특별한 세팅에 의하여 매우 다른 형태를 보입니다. Collapsed 형식을 사용하는지 아닌지에 따라 Send-to-Sync 형태와 Message with Payload 형태로 나뉘어 집니다. 두 컨셉에 대해서는 아래에서 설명하겠습니다.

   Send-to-sync messages

A send-to-sync (collapsible) message is often a "tickle" that tells a mobile application to sync data from the server. For example, suppose you have an email application. When a user receives new email on the server, the server pings the mobile application with a "New mail" message. This tells the application to sync to the server to pick up the new email. The server might send this message multiple times as new mail continues to accumulate, before the application has had a chance to sync. But if the user has received 25 new emails, there's no need to preserve every "New mail" message. One is sufficient. Another example would be a sports application that updates users with the latest score. Only the most recent message is relevant, so it makes sense to have each new message replace the preceding message.

→ A Send-to-Sync message는 Collapsible 한 메시지 입니다. 예를 들자면, 메일 서버에서 메일이 왔을 때 "새 메일이 왔습니다",라는 알림이 처음 올것이고,  이를 확인하지 않은 상태에서 두번째로 메일이 왔을때도 "새 메일이 왔습니다"라고 알림이 오게되겠지요. 당신이 25통의 메일이 왔을때 이를 확인하지 않은 상태라면, "새 메일이 왔습니다"라는 메시지가 25번 필요한 것이 아니라. "새 메일이 왔습니다."란 메시지가 하나만 전달되면 되는 거니까, 모든 메일에 모든 메시지가 도착되어있을 필요가 없지요. 이는 운동경기에서도 동일하게 적용됩니다. 2012년 올림픽 축구에서 한국과 멕시코 경기 알림이 전달되는데 1:0인 상황에서 메시지가 전달되었을 때 사용자가 확인하지 않은 상황에서 2:0이란 메시지가 또 도착한다면 가장 최신 정보인 2:0인 메시지만 필요한 것이지, 1:0이란 메시지가 필요한 것이 아닌 거니깐요. Send-to-Sync 메시지는 새로운 메시지가 이전에 도착한 메시지를 대체하게 됩니다.

The email and sports applications are cases where you would probably use the GCM collapse_key parameter. A collapse key is an arbitrary string that is used to collapse a group of like messages when the device is offline, so that only the most recent message gets sent to the client. For example, "New mail," "Updates available," and so on

→ 이메일과 스포츠 어플리케이션은 이런 기능을 활용하기 위해서 collapse_key라는 파라메터를 사용하게 됩니다. 가령 오프라인인 디바이스에서 collaspse 기능을 사용한 어플리케이션이 메시지를 보낸다면, 오프라인인 디바이스가 온라인이 되었을때, 어플리케이션에는 가장 최근에 보낸 메시지만 전달이 될 것입니다. 예를 들자면, "새 메일이 있습니다" "업데이트가 가능합니다" 등이 있겠죠.

GCM allows a maximum of 4 different collapse keys to be used by the GCM server at any given time. In other words, the GCM server can simultaneously store 4 different send-to-sync messages, each with a different collapse key. If you exceed this number GCM will only keep 4 collapse keys, with no guarantees about which ones they will be.

→ GCM은 주어진 시간에 최대 4개의 다른 collapse key를 제공합니다. 달리말하면 GCM서버는 동시에 각기 다른 collapse key 값의 4개의 send-to-sync 메시지를 저장할 수 있습니다. 만약 5개이상의 collapse key를 사용한다면 모든 것에 대한 전송을 보장하지 못합니다.

Messages with payload

Unlike a send-to-sync message, every "message with payload" (non-collapsible message) is delivered. The payload the message contains can be up to 4K. For example, here is a JSON-formatted message in an IM application in which spectators are discussing a sporting event:

→ send-to-sync 메시지와는 다르게 모든  "message with payload" (non-collapsible message) 는 전달됩니다. payload메시지는 4K까지 전달될 수 있습니다. 아래는 JSON 포멧을 활용한 인스턴스 메신저 어플리케이션의 활용 예입니다. 

{
  "registration_id" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
  "data" : {
    "Nick" : "Mario",
    "Text" : "great match!",
    "Room" : "PortugalVSDenmark",
  },
}

A "message with payload" is not simply a "ping" to the mobile application to contact the server to fetch data. In the aforementioned IM application, for example, you would want to deliver every message, because every message has different content. To specify a non-collapsible message, you simply omit the collapse_keyparameter. Thus GCM will send each message individually. Note that the order of delivery is not guaranteed.

 message with payload는 단순히 데이터를 가져오는 서버에 접속할 수있는 모바일 응용프로그램  "핑"은 아닙니다. 인스턴스 메신저를 예를 들자면 모든 메시지가 모두 다른 컨텐츠를 가지고 있어 이 메시지를 모두 전달해야한다면 non-collapsible message로 사용해하며, collapse key 파라메터를 생략해야합니다. 그리하면 GCM은 모든 메시지를 개적으로 보낼 것입니다. 모든 전달의 순서는 보장되지는 않습니다.

GCM will store up to 100 non-collapsible messages. After that, all messages are discarded from GCM, and a new message is created that tells the client how far behind it is. The message is delivered through a regularcom.google.android.c2dm.intent.RECEIVE intent, with the following extras:

 GCM은 100개의 non-collaspsible 메시지를 저장합니다. 결국에 메시지는 GCM에서 버려집니다. 뒤의 내용은... 개발적인 내용들이네요 ^^ 아래 내용을 참조하세용~

·         message_type—The value is always the string "deleted_messages".

·         total_deleted—The value is a string with the number of deleted messages.

The application should respond by syncing with the server to recover the discarded messages.

   Which should I use?

If your application does not need to use non-collapsible messages, collapsible messages are a better choice from a performance standpoint, because they put less of a burden on the device battery.

 어플리케이션이 collapsible 한 메시지를 사용하느냐에 따라서 잘 선택을 해야합니다. 퍼포먼스 관점에서 디바이스 배터리에 부담을 줄 수 있기 때문에 잘 생각해야 합니다.