Skip to content

Instantly share code, notes, and snippets.

@melardev
melardev / model_dumy_user_create_view.py
Last active February 21, 2019 13:58
Model used in CreateView tutorial
class ModelDummyUser(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100, null=False)
age = models.IntegerField(validators=[MinValueValidator(3), MaxValueValidator(100)])
created_at = models.DateTimeField(auto_now_add=True, editable=False)
def get_absolute_url(self):
return reverse('demos-ui-createview')
@melardev
melardev / create_view_tutotrial_on_melardev_com.py
Last active February 21, 2019 13:57
Create View tutorial on melardev com
# Author: melardev.com
# Youtube video: https://youtu.be/PRw2Hw7yrS0
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.views.generic.edit import CreateView
from demos.forms import *
package com.melardev.cloud.ribbon;
import com.melardev.cloud.ribbon.config.RibbonConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
@SpringBootApplication(scanBasePackages = "com.melardev.cloud.ribbon.controllers") //important, otherwise crash
@EnableEurekaClient
@melardev
melardev / HomeController.java
Created February 21, 2019 13:49
Spring Cloud Ribbon tutorial
package com.melardev.cloud.ribbon.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@melardev
melardev / RibbonConfiguration.java
Created February 21, 2019 13:50
Ribbon tutorial melardev.com
package com.melardev.cloud.ribbon.config;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RibbonConfiguration {
@melardev
melardev / pom.xml
Created February 21, 2019 13:51
Spring Cloud pom xml Ribbon tutorial melardev
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.melardev.cloud</groupId>
<artifactId>ribbon-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@melardev
melardev / application.yml
Created February 21, 2019 13:52
Application yaml file Ribbon Tutorial melardev.com
spring:
application:
name: ribbon-service
server:
port: 8081
rest-server:
ribbon:
eureka: true # By default Ribbon will get the actively running microservices from Eureka, let's disable that strategy
@melardev
melardev / EurekaApplication.java
Created February 21, 2019 13:52
Spring Cloud Eureka
package com.melardev.cloud.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
@melardev
melardev / application.yml
Created February 21, 2019 13:53
Eureka yaml
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
instance:
lease-expiration-duration-in-seconds: 2 # wait up hearbeat for microservices up to 2 sec
@melardev
melardev / HomeController.java
Created February 21, 2019 13:53
Spring Cloud Rest app
package com.melardev.cloud.rest.controllers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HomeController {
@Value("${app.id}")