Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package com.mycompany.pubnubapp;
  7.  
  8. import com.pubnub.api.PNConfiguration;
  9. import com.pubnub.api.PubNub;
  10. import com.pubnub.api.callbacks.PNCallback;
  11. import com.pubnub.api.models.consumer.PNPublishResult;
  12. import com.pubnub.api.models.consumer.PNStatus;
  13. import java.util.Arrays;
  14. import java.util.Scanner;
  15.  
  16. /**
  17. *
  18. * @author nicho
  19. */
  20. public class main {
  21. public static void main(String[] args) {
  22. PNConfiguration pnConfiguration = new PNConfiguration();
  23. pnConfiguration.setSubscribeKey("sub-c-402a5714-d8ca-11e9-87c7-92ba2ff8bd78");
  24. pnConfiguration.setPublishKey("pub-c-5b9209d0-c853-49e0-ad61-9352c3ac8c1f");
  25.  
  26. PubNub pubnub = new PubNub(pnConfiguration);
  27.  
  28. String channelName = "Tempsensor1";
  29. System.out.println("Welcome");
  30. System.out.println("type QUIT as your message to quit.");
  31. String message = "";
  32. Scanner s = new Scanner(System.in);
  33. while(!"quit".equals(message)){
  34. System.out.println("Input your message to publish to the channel: ");
  35. message = s.next();
  36. pubnub.publish().message(message).channel(channelName).async(new PNCallback<PNPublishResult>() {
  37. @Override
  38. public void onResponse(PNPublishResult result, PNStatus status) {
  39. // handle publish result, status always present, result if successful
  40. // status.isError to see if error happened
  41. }
  42. });
  43. }
  44. System.exit(0);
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement