Пример #1
0
func run(c *cli.Context) {

	user := c.String("User")
	if 0 == len(user) {
		cli.ShowAppHelp(c)
		log.Fatal("User must be provided")
	}

	text := c.String("Text")
	if 0 == len(text) {
		cli.ShowAppHelp(c)
		log.Fatal("Text must be provided")
	}

	amqpUri := c.String("AmqpUri")
	amqpExchange := c.String("AmqpExchange")
	amqpType := "direct"
	key := c.String("AmqpKey")
	amqpService := xmpptoamqp.NewAmqpService(&amqpUri, nil, nil, nil)
	amqpService.ExchangeDeclare(&amqpExchange, &amqpType)
	amqpService.Send(&amqpExchange, &key, &user, &text)

	log.WithFields(log.Fields{
		"user": c.String("User"),
	}).Info("Chat sent")

}
Пример #2
0
func run(c *cli.Context) {

	xmppServer := c.String("XmppServer")

	xmppUser := c.String("XmppUser")
	if "" == xmppUser {
		cli.ShowAppHelp(c)
		log.Fatal("XMPP User must be provided")
	}

	xmppPassword := c.String("XmppPassword")
	if "" == xmppPassword {
		cli.ShowAppHelp(c)
		log.Fatal("XMPP Password must be provided")
	}

	amqpUri := c.String("AmqpUri")
	amqpSendExchange := c.String("AmqpSendExchange")
	amqpSendType := "direct"
	amqpSendQueue := c.String("AmqpSendQueue")
	amqpService := xmpptoamqp.NewAmqpService(&amqpUri, &xmppServer, &xmppUser, &xmppPassword)
	amqpService.ExchangeDeclare(&amqpSendExchange, &amqpSendType)

	// XMPP -> Channel -> AMQP
	go amqpService.ReceiveXmpp()
	amqpReceivedExchange := c.String("AmqpReceivedExchange")
	amqpReceivedType := "fanout"
	amqpService.ExchangeDeclare(&amqpReceivedExchange, &amqpReceivedType)
	go amqpService.ForwardChatReceivedEvents(&amqpReceivedExchange)

	// AMQP -> Channel -> XMPP
	tag := "xmpptoamqp"
	go amqpService.ConsumeSendCommands(&amqpSendExchange, &amqpSendQueue, &tag)
	go amqpService.SendXmpp()

	// Wait for terminating signal
	sc := make(chan os.Signal, 2)
	signal.Notify(sc, syscall.SIGTERM, syscall.SIGINT)
	<-sc

	log.Info("Received terminate signal")
	amqpService.Close()

	log.Info("Gracefully terminating")

}