Giter Site home page Giter Site logo

faizakram / push-notification-spring-boot Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 36 KB

Push Notification Using EventBus and Spring Boot

License: Apache License 2.0

Shell 17.15% Batchfile 12.09% Java 8.51% JavaScript 56.13% HTML 6.12%
spring eventhandler sseemitter springpublisher java springboot push notifications push-notifications

push-notification-spring-boot's Introduction

PUSH-NOTIFICATION Using SseEventBus and SseEmitter

#When you using spring MVC using the version 4.2.4.RELEASE org.springframework spring-web 4.2.4.RELEASE

The resion is SseEmiter Have parameterised constructor in

#org.springframework.web.servlet.mvc.method.annotation.SseEmitter

#When calling

	eventBus.createSseEmitter(id, SseEvent.DEFAULT_EVENT);
	// it calls SseEventBus -->
	public SseEmitter createSseEmitter(String clientId, Long timeout, boolean unsubscribe,
			boolean completeAfterMessage, String... events)
	SseEmitter emitter = new SseEmitter(timeout);

#Use in javascript

var eventSource;
window.onbeforeunload = () => {
  if (eventSource) {
    eventSource.close();
  }
}
eventSource = new EventSource(`http://10.1.16.61:8080/SpringMVCHibernateWithSpringSecurity/register/${uuid}`);
eventSource.addEventListener('message', response => {
	for (let line of response.data.split('\n')) {
		console.log(line);
		handleResponse(JSON.parse(line));
	}
}, false);

#Use in Angular JS

const EventSource: any = window['EventSource'];
    const es = new EventSource('http://10.1.16.61:8080/SpringMVCHibernateWithSpringSecurity/register/${uuid}',
      { headers: { 'Content-Type': 'text/event-stream' } });
    es.onconnect = (e) => {
      console.log(e);
    }
    es.onmessage = evt => {
      console.log('Event source testing', evt);
      const data = JSON.parse(evt.data); // TODO handle parse error
    };

push-notification-spring-boot's People

Contributors

faizakram avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.