public class

PubNubModule

extends Object
java.lang.Object
   ↳ org.mule.module.pubnub.PubNubModule
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

PubNub is an Internet-Wide Messaging Service for Real-time Web and Mobile apps and games. PubNub is a massively scalable Real-time Bidirectional Messaging Service in the Cloud.

This connector supports version 3 of the PubNub REST API.

PubNub is a freemium service where users get 5,000 messages per day for free but then have reasonable pricing plans for higher volume usage. For more information go to PubNub: http://pubnub.com

Summary

Constants
int MESSAGE_LIMIT
String ORIGIN
Fields
private Client httpClient
private static Logger logger
private ObjectMapper mapper
private String originUrl
private String publishKey Your publish key that allows you to send data to the PubNub cloud
private String secretKey The secret key given to you when you created the account
private boolean ssl Whether to use SSL or not when communicating with the PubNub cloud
private String subscribeKey Your subscribe key that allows you to send data to the PubNub cloud
Public Constructors
PubNubModule()
Creates a new PubNub connector with no state.
PubNubModule(String publishKey, String subscribeKey, String secretKey, boolean ssl)
Creates a new PubHub connector with required state.
PubNubModule(String publishKey, String subscribeKey, String secretKey)
Creates a new PubHub connector with required state.
Public Methods
ObjectNode createMessage()
Creates a new Json Object message.
String getPublishKey()
String getSecretKey()
String getSubscribeKey()
JsonNode history(String channel, int limit)
Load history from a channel.
void init()
boolean isSsl()
JsonNode publish(String channel, String jsonMessage)
Send a json message to a channel.
JsonNode publish(String channel, JsonNode jsonMessage)
Send a json message to a channel.
JsonNode request(String channel, long timeout)
Makes a blocking request to receive a message on a channel.
double serverTime()
Get the Timestamp from PubNub Cloud.
void setPublishKey(String publishKey)
void setSecretKey(String secretKey)
void setSsl(boolean ssl)
void setSubscribeKey(String subscribeKey)
void subscribe(String channel, SourceCallback callback)
Listen for a message on a channel.
void subscribe(String channel, MessageListener listener)
Register a message listener for a channel.
Protected Methods
String getBaseUrl()
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MESSAGE_LIMIT

Constant Value: 1800 (0x00000708)

private static final String ORIGIN

Constant Value: "pubsub.pubnub.com"

Fields

private Client httpClient

private static Logger logger

private ObjectMapper mapper

private String originUrl

private String publishKey

Your publish key that allows you to send data to the PubNub cloud

private String secretKey

The secret key given to you when you created the account

private boolean ssl

Whether to use SSL or not when communicating with the PubNub cloud

private String subscribeKey

Your subscribe key that allows you to send data to the PubNub cloud

Public Constructors

public PubNubModule ()

Creates a new PubNub connector with no state. If this constructor is used, then you must also call #config(String, String, String, boolean)

public PubNubModule (String publishKey, String subscribeKey, String secretKey, boolean ssl)

Creates a new PubHub connector with required state. The keys required to create the connector are available from your account on the PubNub website: http://www.pubnub.com/account. SSL can be used by setting the SSL flag.

Parameters
publishKey Your publish key that allows you to send data to the PubNub cloud
subscribeKey Your subscribe key that allows you to send data to the PubNub cloud
secretKey The secret key given to you when you created the account
ssl Whether to use SSL or not when communicating with the PubNub cloud

public PubNubModule (String publishKey, String subscribeKey, String secretKey)

Creates a new PubHub connector with required state. The keys required to create the connector are available from your account on the PubNub website: http://www.pubnub.com/account.

Parameters
publishKey Your publish key that allows you to send data to the PubNub cloud
subscribeKey Your subscribe key that allows you to send data to the PubNub cloud
secretKey The secret key given to you when you created the account

Public Methods

public ObjectNode createMessage ()

Creates a new Json Object message. The org.codehaus.jackson.node.ObjectNode can be used like a Map to write key/value pairs. Objects can be text, numeric, binary or complex objects

Returns
  • a newly created org.codehaus.jackson.node.ObjectNode instance.

public String getPublishKey ()

public String getSecretKey ()

public String getSubscribeKey ()

public JsonNode history (String channel, int limit)

Load history from a channel.

Parameters
channel Name.
limit History count response.
Returns
  • JsonNode of history.

public void init ()

public boolean isSsl ()

public JsonNode publish (String channel, String jsonMessage)

Send a json message to a channel.

Parameters
channel Name to publish the message to
jsonMessage The message to publish
Returns
  • boolean false on fail.

public JsonNode publish (String channel, JsonNode jsonMessage)

Send a json message to a channel.

Parameters
channel To publish to
jsonMessage The message to publish
Returns
  • the response from the server

public JsonNode request (String channel, long timeout)

Makes a blocking request to receive a message on a channel.

Parameters
channel Name to read from
timeout How long to wait for a message. The value is expressed in milliseconds. specify for
Returns
  • zero or more messages depending on what was in the queue

public double serverTime ()

Get the Timestamp from PubNub Cloud.

Returns
  • double timestamp.

public void setPublishKey (String publishKey)

Parameters
publishKey

public void setSecretKey (String secretKey)

Parameters
secretKey

public void setSsl (boolean ssl)

Parameters
ssl

public void setSubscribeKey (String subscribeKey)

Parameters
subscribeKey

public void subscribe (String channel, SourceCallback callback)

Listen for a message on a channel.

Parameters
channel Name to listen on
callback Callback to execute when a message comes in

public void subscribe (String channel, MessageListener listener)

Register a message listener for a channel. This is a blocking subscribe which also means that only one subscription can be made per connector.

Listen for a message on a channel.

Parameters
channel Name to listen on
listener The message callback to invoke when a message is received. there will be one invocation per message and the invocation on the message listener is guaranteed never to be null.

Protected Methods

protected String getBaseUrl ()