App & Keys Structure
It is very likely that you will want to create multiple PubNub API keys (pub/sub keys) for a single application so that your developers can implement new features and fix bugs while your QA team is verifying that the next version is ready for production. And meanwhile, your customers need to be unaffected by all this pre-release activity. You already have a database for each of these separate environments so it is only appropriate that you will want separate PubNub API keys for each environment, also. When creating new API keys in the PubNub Dashboard, treat each set of your API keys the same as your database instances.
You can create multiple PubNub API keys in the PubNub Dashboard under a single PubNub App. Each set of keys will be configured according to its designated environment: environment-aligned keys. Use the PubNub Dashboard to add API keys to an existing app and configure consistently them as required (Presence, Storage, Mobile Push, etc).
For example, in your PubNub Dashboard, you might have a couple of PubNub Apps with three sets of API keys for each, as follows:
|DateNight App||- Dev Keys|
- QA Keys
- Prod Keys
|TheGuideUpdate App||- Dev Keys|
- QA Keys
- Prod Keys
Here is a look at an example of one of the apps from above with the three environment-aligned API keys.
The Apps of the PubNub Account
The API Keys of the DateNight App
Clicking on the DateNight App above navigates to the API keys of that app.
If you already have an environment config file containing the database connection parameters for the current environment that your app ingests at the app startup phase, then you can include the appropriate PubNub API keys in there, too.
# DateNight properties file
# MySQL DB connection
# PubNub API keys
Above is just a simple example of an environment configuration file that typically lives on your server. But this is exactly what you want. When a server instance starts up, it reads this config file (which will vary based on the environment: Dev, QA, Prod). When clients login to your app, the appropriate PubNub API keys for that environment can be delivered to the client rather than hard-coding those key in the client app. This allows you to change the PubNub API keys fairly easy compared to shipping a new release, especially in the case of a mobile app.
There are the
demo keys that you see in many code samples on the PubNub website:
"publishKey": "demo", "subscribeKey":"demo". These keys are throttled (limits the number of requests per second) to mitigate potential abuse. Similarly, the first set of keys that are generated for you when you create an account are called Demo keys, but they are your demo keys. And they are request rate limited, too.
Most of the PubNub services (Presence, Storage, Functions, Stream Controller, etc.) are enabled for you so that you do not have to remember to so when you are getting started with learning and using the various PubNub features and APIs.
When you are ready to push the PubNub Network a bit more, you must create a new set of keys, preferably in a new PubNub App, in your PubNub Dashboard account. But any new API keys that you create will NOT have any of the PubNub services enabled and will NOT be rate limited. You will enable services on your API keys as required.
Learn about setting up your application to initialize and use PubNub correctly Initialize and Add Listener.