Showing posts with label engine. Show all posts
Showing posts with label engine. Show all posts

Tuesday, March 18, 2014

Our favorite recipes for App Engine all in one place

Do you have a really great code snippet youd love to share with App Engine developers? Have you figured out how to program a small task for your app and want to tell the world? Share your elite coding skills with the world by posting your recipe to our Google App Engine Cookbook. Theres no such thing as too many cooks in this kitchen!



The App Engine Cookbook allows you to share, rate, and comment on App Engine recipes and was written by Google Engineer Amaltas Bohra. Weve added some of our favorites, now we cant wait to see whats cookin in the App Engine developer community!



Read More..

Friday, March 14, 2014

App Engine Case Studies

Posted by Paul McDonald, App Engine Team



Over the past few months weve heard some amazing stories detailing
just how easy it is to create scalable web applications on App Engine. Weve
invited a few developers to participate in some case study videos and
tell you more about their experience with App Engine.




BuddyPoke!
BuddyPoke! is an OpenSocial app running on
MySpace, Orkut, and Hi5. It has scaled to nearly 30M daily
pageviews on App Engine.

"App
Engine has been a godsend in terms of our scalability...we saw a 8x
jump in installs overnight and we are now serving 12 million users!" -
Dave Westwood, BuddyPoke!













Pixverse (PixChat)
PixChat, recently acquired by Hi5, lets you chat with friends
across the web within your Hi5 profile page. 



"Running our app on App Engine was really easy...the whole porting effort took only 3 hours." - Charles Ying, Pixverse











Hyperic (CloudStatus)

CloudStatus monitors the health and performance of major cloud
computing platforms like App Engine and Amazon Web Services.











These are but three examples of the many applications that have
been developed on App Engine.  Are you interested in sharing your
experience?  If so wed love to hear from you, tell us your story in our developer forum.




Read More..

Monday, March 10, 2014

Drupal on Google App Engine

Todays guest post is from Felipe Rubim, Head of Technology at CI&T. A Top Google Cloud Platform Partner, CI&T builds scalable predictive applications and custom software for fortune 500 companies. As far as PHP and Drupal applications, CI&T has built and maintains more than 400 Drupal enterprise websites globally with an army of 300+ Drupal developers. In this post, Felipe introduces a white paper detailing a test CI&T conducted on Google Cloud Platform and the potential for Drupal Enterprise apps running on Google App Engine PHP. The link to the complete methodology and findings can be found here.



Is Google App Engine ready for Drupal and if it is, can it be used for enterprise class applications?



Based on our experience working with Drupal and Google App Engine, we felt confident that the combination of the two would have the potential to cause a major shift in the content management portfolio of enterprises. Our goal was to test to see if App Engine was indeed ready to run Drupal for world class Enterprises. First, we tested features frequently requested by our customers, especially in the digital marketing arena: consumer-facing websites, portals for sales teams, doctors and healthcare professionals and intranets.



Methodology:

We evaluated the last three major releases of Drupal, and determined that Drupal 7 was optimally suited for use with App Engine and suitable for enterprise workloads. Drupal 8 was assessed as promising but at present not sufficiently mature, and Drupal 6 deployments on App Engine were not recommended as detailed in the white paper.



Findings:


  • Scalability - We determined that Drupal websites running on top of App Engine scale beautifully. This is especially useful for digital marketing campaigns.

  • Security - We found App Engine to be in good shape for web portals handling sensitive data.

  • Versioning - We determined having different versions of your site without going through extra infrastructure set up to be a big game changer.

  • Drupal Multisite - We concluded this was easy to set up and that it works as expected.

  • Drush - We found that in order to make Drush work with App Engine, some tweaks are needed when connecting to CloudSQL from another set up (e.g. Google Compute Engine - GCE).

  • Search - We concluded that installing and configuring Apache Solr in a GCE instance is the way to go for implementing enterprise Drupal search. We created a tutorial for that.

  • SSO - We also tested SSO with Google Apps and provided a code snippet/tutorial


Is Google App Engine ready for Drupal and if it is, can it be used for enterprise class applications?



Our tests showed that App Engine PHP is a powerful alternative for Drupal deployments and is moving fast towards being a solid platform for Drupal Enterprise class sites and portals, particularly with Drupal 7.



In our experiments we identified that components from Drupal, App Engine, GCE and Google Apps could be synergically valuable in several scenarios, like:




  • Google Drive and Drupal Workflow - leveraging Drupal custom workflows and auditing/logging capabilities vastly improves Google Drive and Drupal Content/Files Workflow/authoring with automatic publishing of approved documents,

  • App Engine Task Queue - to replace scheduled cron tasks with App Engine Task Queue, and then execute background work (export data from a Drupal user table, campaign/contest registration, etc.) and leverage App Engine interface for management, debugging and logging;

  • Flexible and extensible stack with an integrated Google Compute Engine approach - The usage of Compute Engine as a complementary component of the solution allows better flexibility to add more features and integration, as well as increased automation for the site management. More details on these features and benefits described below;




We believe Enterprises can reap multiple benefits by moving their Drupal sites to Google App Engine/Google Cloud Platform. Here are the key features and benefits, higher value first:



Auto-scale: By far, the number one benefit. This is particularly critical for Drupal digital marketing/campaign web sites, where unexpected traffic can easily break ill-prepared hosting setups.



Worry-free infrastructure: No need to remove/add servers, configuration or load balance management. Big headaches averted.



Integration with Google Apps: The potential to leverage the integration with Google products family in a number of use cases, is a big plus.



Application Management: By leveraging the Google SDKs along with its simple but powerful application configuration and management dashboard.



Potential cost savings: Considering you pay only for the resources you use, this is a great benefit. This is especially true when moving from an IaaS or traditional hosting model, where resources are needed to maintain the infrastructure portfolio.



Enterprise to Enterprise: GCP/App Engine are based on Google’s infrastructure, which also host Google Products. That means all the features and measures applicable to Google Products (such as security requirements) will also apply to your Drupal Site.



For the complete study, please see the link below:

http://www.ciandt.com/us-en/card/is-google-app-engine-PHP-ready-for-drupal



-Contributed by Felipe Rubim, Head of Technology at CI&T
Read More..

Sunday, March 9, 2014

Multi Channel Chat with Twilio and Google App Engine

Today’s post comes from Kevin Whinnery, Developer Evangelist at Twilio. In this post, Kevin describes how to build a multi-channel chat application using Google App Engine and Twilio. You can follow Kevin on Twitter at @kevinwhinnery or on Google+.







Google App Engine enables developers to focus on their application’s logic by providing a scalable infrastructure and high-level APIs for persistence, file management, and other common web app needs. XMPP and Channels are among these APIs, making it ridiculously easy to write awesome real-time communications apps in the browser.



Today, we’re going to break down an example application (view it live, source code) that integrates these two App Engine services (plus SMS messaging from Twilio) in a group chat application that connects users via SMS, XMPP, and browser-based chat clients.



We won’t go through every line of code, but at a high level, this application is about receiving inbound messages and sending outbound messages. Let’s see how we do this via SMS, XMPP, and Channels.



Twilio SMS

Sending SMS text messages with the Twilio API requires signing up for a Twilio account. Once you’ve signed up for an account, you can use your account SID and auth token to make authenticated requests against the Twilio REST API. You could just use App Engine’s built-in URL fetch service to interact with the Twilio API, but our official helper library for Java makes authenticating requests and serializing data much easier, providing a POJO interface to Twilio resources and functionality. We’ll be using the Twilio helper in this example. If you’re looking for App Engine specific reference examples, our friends at Google included this reference documentation in their doc site.



In our chat application, all outbound communication and message dispatching is handled by the MultichannelChatManager class. In this application, we add subscribers to the chat room to an in-memory set. When it’s time to send out a message, we iterate over the members of this set and send out messages to all subscribers. We send out messages to SMS subscribers using the Twilio helper on line #56:

TwilioRestClient client = new TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN");

Map params = new HashMap();
params.put("Body", messageBody);
params.put("To", sub);
params.put("From", "+16122948105");

SmsFactory messageFactory = client.getAccount().getSmsFactory();

try {
Sms message = messageFactory.create(params);
System.out.println(message.getSid());
} catch (TwilioRestException e) {
e.printStackTrace();
}
To receive inbound communication, you will need to purchase a Twilio phone number or use the one given to you when you signed up for a Twilio account. You can configure this phone number to send an HTTP POST to a URL that you choose when an SMS message is received (this callback pattern is called a webhook). In this sample application, we have a Java servlet with a web.xml file configured to accept inbound SMS. In your Twilio number configuration, you would enter https://yourappname.appspot.com/sms, as below:



In the actual servlet, we handle inbound SMS messages first by looking for a “STOP” command, which will indicate that this user no longer wants to receive text messages from the app. Then, we confirm that the user is subscribed (by looking for their telephone number). Finally, we send out a message using our MultichannelChatManager class.



When Twilio sends your app the details of an SMS message with an HTTP request, it expects your app to respond with an XML format called TwiML. TwiML is a simple set of fewer than 20 XML tags that tells Twilio how to respond to inbound communication. The output of our SMS servlet is an XML (TwiML) document, which will send an SMS back to a user if they unsubscribe:

public class TwilioSmsServlet extends HttpServlet {
// Handle Incoming SMS
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
TwiMLResponse twiml = new TwiMLResponse();

// parse the body, looking for a command
String smsBody = request.getParameter("Body");
String smsFrom = request.getParameter("From");

// Unsubscribe, if requested
if (smsBody.startsWith("STOP")) {
MultichannelChatManager.removeSub(smsFrom);
com.twilio.sdk.verbs.Sms bye = new com.twilio.sdk.verbs.Sms("You have been unsubscribed. Thank You!");
twiml.append(bye);
} else {
// If they arent subscribed, subscribe them
if (!MultichannelChatManager.isSubscribed(smsFrom)) {
MultichannelChatManager.addSub(smsFrom);
}
MultichannelChatManager.sendMessage(smsBody, "sms");
}

response.setContentType("application/xml");
response.getWriter().print(twiml.toXML());

} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
}
}

App Engine XMPP Integration

App Engine provides a simple API for sending and receiving XMPP chat messages. Our chat application can receive new messages over XMPP and send them back out to all subscribed clients, similar to how our app behaves for SMS.



App Engine applications have an XMPP username associated with them by default, which takes the form of “appname@appspot.com”. The former part of the username is your unique App Engine app ID and the latter is the appspot domain that your app runs on. To send a message via XMPP to our chat app we need to send a chat message to “twiliosandbox@appspot.com” from a chat client that supports XMPP. If you used the desktop chat client Adium for Google Talk, the interaction might look something like this:



For our application to receive inbound XMPP messages, we need to configure an inbound message handler servlet in our web.xml configuration file. This webhook callback design is the same type of event mechanism used by Twilio to deliver SMS messages to our application. In this servlet, we receive an inbound POST request with information about an inbound chat message:

public class XMPPReceiverServlet extends HttpServlet {
// Handle Incoming XMPP Chat messages
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message msg = xmpp.parseMessage(req);

// The "JID" is the unique ID of this chat client, which we use to subscribe
JID fromJid = msg.getFromJid();
String body = msg.getBody();

// Unsubscribe, if requested
if (body.startsWith("STOP")) {
MultichannelChatManager.removeSub(fromJid.getId());
} else {
// If they arent subscribed, subscribe them
if (!MultichannelChatManager.isSubscribed(fromJid.getId())) {
MultichannelChatManager.addSub(fromJid.getId());
}
MultichannelChatManager.sendMessage(body, "xmpp");
}
}
}
To send outbound messages, we use the App Engine platform APIs to send an outbound message to a specific JID, which uniquely identifies a connected XMPP client:

JID jid = new JID(sub);
Message msg = new MessageBuilder().withRecipientJids(jid).withBody(messageBody).build();
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
xmpp.sendMessage(msg);

Channel API

The Channel API allows server-side push to connected clients in an App Engine application. In our chat application, we will utilize this API to push new chat messages to browser-based clients.



In order for our server to push chat messages to a browser, the client needs to be issued an ID by our server. We configure a servlet to handle issuing these IDs (and to handle incoming chat messages created by the browser in JavaScript) in web.xml. The servlet generates a unique ID for a connected client, based on the current system time:

//Generate a client token for the GAE Channel API
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
ChannelService channelService = ChannelServiceFactory.getChannelService();

//The token must be based on some unique identifier for the client - I am using the current time
//for demo purposes...
String clientId = String.valueOf(System.currentTimeMillis());
String token = channelService.createChannel(clientId);

//Subscribe this client
MultichannelChatManager.addSub(clientId);

//Reply with the token
res.setContentType("text/plain");
res.getWriter().print(token);
}
In the browser, we get an ID for the current user via XHR. First, we include the Channel client JavaScript library by requesting a special URL on the App Engine server. Then we use jQuery to issue a GET request to our server to obtain a client ID:

//Get a client token to use with the channel API
$.ajax(/chat,{
method:GET,
dataType:text,
success: function(token) {
console.log(token);
var channel = new goog.appengine.Channel(token);
var socket = channel.open();

//Assign our handler function to the open socket
socket.onmessage = onMessage;
}
});
When we get our client ID, we use that to configure the App Engine channel service in the browser for data pushed from the server. Data pushed from the server is handled in a callback function, which updates the textarea on the page. When the user enters a chat message in the browser, we issue a POST request to our ChatServlet, which uses the MultichannelChatManager class to publish a message to all connected clients. This is where we use the channel API to push data to connected web browsers:

ChannelService channelService = ChannelServiceFactory.getChannelService();
channelService.sendMessage(new ChannelMessage(sub,messageBody));

Wrapping Up

In this walkthrough, we explored three messaging APIs that work nicely on App Engine: Twilio SMS, XMPP, and Channels. Our example used Java, but all three APIs will work with Python and Go as well (Twilio has a helper library you might use for Python also).



Using platforms like Twilio and App Engine, developers can create communications applications, which previously would have required expert knowledge and infrastructure to build, in a fraction of the time. I hope you’ll be able to use these APIs to engage with your users wherever they happen to be.



Application source code is available on GitHub here.



- Contributed by Kevin Whinnery, Developer Evangelist, Twilio
Read More..