Coder Social home page Coder Social logo

springcloudvideocourse's People

Contributors

simplyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

springcloudvideocourse's Issues

Add Java Cryptography Extension - is unnecessary fuss in 1.8u192

Well, I'm implementing the project on 19th Java, I couldn't have figured out why I am unable to find a link to download a file, as it turned out it is enabled by default starting from 8u161

Unlimited cryptography enabled by default

The JDK uses the Java Cryptography Extension (JCE) Jurisdiction Policy files to configure cryptographic algorithm restrictions. Previously, the Policy files in the JDK placed limits on various algorithms. This release ships with both the limited and unlimited jurisdiction policy files, with unlimited being the default. The behavior can be controlled via the new 'crypto.policy' Security property found in the /lib/java.security file. Please refer to that file for more information on this property.

https://www.oracle.com/java/technologies/javase/8u161-relnotes.html#JDK-8170157

as for the bootstrap.properties it's also irrelevant already since the latest Spring Boot natively supports the parameters.

an issue with Spring Cloud Config Server when fetching an update from the repository unless the default port is used

Here is a part of my application.yml

spring:
  config:
    import: optional:configserver:http://localhost:8012

The thing is whenever I start running microservices I see in the console how it cannot initially find the server at the default port falling back to the 8012 port. However, once I push changes to my git repository, Spring Cloud Config Service fetches those changes re-running all microservices. For no reason they just don't want to connect to the server at 8012 port again. I just failed to find the obstacle. Once I changed the settings to the default port which is 8888 - everything works as expected!

spring:
  config:
    import: optional:configserver:http://localhost:8888

SecurityConstansts

Hi Sergey,

Please provide the SecurityConstants file as shown in the WebSecurityConfigurereAdapter Deprecated. it will be very helpful.

In the UsersServiceImpl class, the autowired annotation shows as unneccesary but how do i autowire it if it not neccessary.

UserService

In the AuthorizationFilter Class, the SecurityConstants and UserPrinciapal Class are showing in error, these were not created in the project nor shown in article https://www.appsdeveloperblog.com/migrating-from-deprecated-websecurityconfigureradapter/

AuthorizationFilter

Also, in the Websecurity file is showing with errors, can't understand why. and the Springboot main class says that @bean is not required. Please help in this project, trying to learn a lot from this project. Need help

WebSecurity

Main

spring cloud gateway is not working

https://drive.google.com/file/d/17r4mFmlnXmixOQ8uAE_bGuhEf3ig_Sop/view?usp=sharing

this is the link of spring cloud api gate way which i am not able run it.....

2021-01-04 08:20:34.509 ERROR 4612 --- [ctor-http-nio-6] a.w.r.e.AbstractErrorWebExceptionHandler : [029c859b-2] 500 Server Error for HTTP GET "/users-ws/users/check/status"

java.net.UnknownHostException: failed to resolve 'HMECL002925.happiestminds.com' after 3 queries

at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1013) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 

Error has been observed at the following site(s):

|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]

|_ checkpoint ⇢ HTTP GET "/users-ws/users/check/status" [ExceptionHandlingWebHandler]

Stack trace:

	at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1013) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:966) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:414) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsResolveContext.onResponse(DnsResolveContext.java:625) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsResolveContext.access$400(DnsResolveContext.java:63) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:458) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:605) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsQueryContext.trySuccess(DnsQueryContext.java:201) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsQueryContext.finish(DnsQueryContext.java:193) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.resolver.dns.DnsNameResolver$DnsResponseHandler.channelRead(DnsNameResolver.java:1230) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[netty-codec-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]

	at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

Using Header Predicate - status 403 at "/users-ws/users/status/check" with Bearer abc

Well, I have spent a decent amount of time comparing code trying to figure out why I get the 403 status with Bearer.
https://github.com/simplyi/SpringCloudVideoCourse/blob/update-spring-boot-v3.0.1/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/security/WebSecurity.java

I deleted many times from the snippet of code

http
                .cors().and()
                .csrf().disable().authorizeHttpRequests()
                .requestMatchers(HttpMethod.POST, "/users")
                     .access(new WebExpressionAuthorizationManager(
        				"hasIpAddress('"+environment.getProperty("gateway.ip")+"')"
        				))
                .requestMatchers(HttpMethod.POST, environment.getProperty("login.url.path")).permitAll()
                .requestMatchers(new AntPathRequestMatcher("/h2-console/**")).permitAll()
                .anyRequest().authenticated().and()

                .addFilter(getAuthenticationFilter(authenticationManager))
                .authenticationManager(authenticationManager)

                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        http.headers().frameOptions().disable();

        return http.build();

the line:
.requestMatchers(HttpMethod.POST, environment.getProperty("login.url.path")).permitAll();

Actually, when you watch the course you delete it in one of previous lesson. I don't know why (or how) it appears here. The line is pointless, but don't rush deleting it. Just change POST request to GET and instead of environment.getProperty("login.url.path") hardcode "/users/status/check". Restart all services.

restTemplate.exchange doesn't work

Sergey,

I believe I need a hand with the lesson. I'm watching "Make Users Microservice call Albums Microservice" at the moment. The snippet of code is exactly what bothers me at the moment:

 /*
        String albumsUrl = String.format(environment.getProperty("albums.url"), userId);
        
        ResponseEntity<List<AlbumResponseModel>> albumsListResponse = restTemplate.exchange(albumsUrl, HttpMethod.GET, null, new ParameterizedTypeReference<List<AlbumResponseModel>>() {
        });
        List<AlbumResponseModel> albumsList = albumsListResponse.getBody(); 
        */

In the video it works perfectly fine however I went to the most recent version of your repository

to my surprise the code has been commented out. Wouldn't you mind explaining me what arguments I should provide to the restTemplate.exchange ?

Thank you in advanced.

Configure Project to use resilience4j Circuit Breaker - Feign

Hi there.

Actually, you almost don't need resilience4j. I have seen the latest Sergey's implementation, but I decided to stick to what I had seen in the video with Hystrix

pom.xml

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>4.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
        </dependency>

Then, you need to enable fallback as it is suggested in the video though it has slightly different parameters:

In the application.properties / application.yml of the PhotoAppApiUsers set the following:

spring:  
  cloud:
    openfeign:
      circuitbreaker:
        enabled: true

I would also suggest switching to the ERROR mode.

logging:
  level:
    com:
      appsdeveloperblog:
        photoapp:
          api:
            users:
              client:
                AlbumsServiceClient: ERROR

I couldn't have figured out as to why I see an exception. The result was completely different from what Sergey gets in the video.

Screenshot 2023-04-10 at 09 48 02

Finally, when I change the DEBUG to ERROR mode my console is clean now.

The last step is quite the same as you see in the video.

@FeignClient(name = "albums-ws", fallback = AlbumsFallback.class)
public interface AlbumsServiceClient {

    @GetMapping("/users/{id}/albums")
    List<AlbumResponseModel> getAlbums(@PathVariable String id);
}

@Component
class AlbumsFallback implements AlbumsServiceClient {

    @Override
    public List<AlbumResponseModel> getAlbums(String id) {
        return new ArrayList<>();
    }
}

Run RabbitMQ within a docker container.

Well, it's not an issue, but a simple message to make your life easier.

docker-compose up -d

compose.yml

version: "3.9"
services:
  rabbitmq:
    image: rabbitmq:3.12.0-beta.5-management
    hostname: rabbitmq
    restart: always
    environment:
      - RABBITMQ_DEFAULT_USER=guest
      - RABBITMQ_DEFAULT_PASS=guest
    ports:
      - 5672:5672
      - 15672:15672

the latest RabbitMQ docker container

and
application.yml

spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

Elastic Logstash Kibana ELK from Docker

Well, I took another route, speaking of simplicity - it's really easy to set up. However, something went wrong with it and I had to figure out. Now, I share with all of you what should be done in order to get the result as fast as you can.

Open the project and clone it into any directory you want, supposing you're on MacOs

open terminal and type:
cd ~/desktop/dev

then clone the project:
git clone [email protected]:deviantony/docker-elk.git

Go to ~/desktop/dev/docker-elk/logstash/pipeline/logstash.conf and open logstash.conf. Paste the following text:

input {
	beats {
		port => 5044
	}
	tcp {
		port => 50000
	}
	file {
	    type => "users-ws"
	    path => "/var/log/microservices/users-ws.log"
	    start_position => "beginning"
	}
	file {
    	    type => "albums-ws"
    	    path => "/var/log/microservices/albums-ws.log"
    	    start_position => "beginning"
    }
}
output {
    if [type] == "users-ws" {
        elasticsearch {
            hosts => ["elasticsearch:9200"]
            data_stream => "false"
            user => "logstash_internal"
            password => "${LOGSTASH_INTERNAL_PASSWORD}"
            index => "users-ws-%{+YYYY.MM.dd}"
        }
    } else if [type] == "albums-ws" {
        elasticsearch {
            hosts => ["elasticsearch:9200"]
            data_stream => "false"
            user => "logstash_internal"
            password => "${LOGSTASH_INTERNAL_PASSWORD}"
            index => "albums-ws-%{+YYYY.MM.dd}"
        }
    }
    stdout { codec => rubydebug }
}

Mind, we need to mount two directories so that they are available within our docker container
/var/log/microservices/users-ws.log
/var/log/microservices/albums-ws.log

Now, we go to ~/desktop/dev/docker-elk/setup/entrypoint.sh and open entrypoint.sh

Find the line:

[logstash_internal]='logstash_writer'
(it is almost at the beginning, look for it in the users_roles section)

and change the value to
[logstash_internal]='superuser'

I can't explain the reason as to why we have to change the role. Otherwise, there would be a constant error with logstash_writer

and the last file we are going to set up is .env. It's hidden. If you're trying to open it within the IntelliJ IDEA, open the directory ~/desktop/dev/docker-elk/.env and then press SHIFT + CMD + . (dot). Override "changeme" values with your own password, mine was 123456789 and set ELASTIC_VERSION to the latest. For no reason they don't support "latest", therefore we have to specify the actual version in numbers.

ELASTIC_VERSION=8.7.0

## Passwords for stack users
#

# User 'elastic' (built-in)
#
# Superuser role, full access to cluster management and data indices.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
ELASTIC_PASSWORD='123456789'

# User 'logstash_internal' (custom)
#
# The user Logstash uses to connect and send data to Elasticsearch.
# https://www.elastic.co/guide/en/logstash/current/ls-security.html
LOGSTASH_INTERNAL_PASSWORD='123456789'

# User 'kibana_system' (built-in)
#
# The user Kibana uses to connect and communicate with Elasticsearch.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
KIBANA_SYSTEM_PASSWORD='123456789'

# Users 'metricbeat_internal', 'filebeat_internal' and 'heartbeat_internal' (custom)
#
# The users Beats use to connect and send data to Elasticsearch.
# https://www.elastic.co/guide/en/beats/metricbeat/current/feature-roles.html
METRICBEAT_INTERNAL_PASSWORD=''
FILEBEAT_INTERNAL_PASSWORD=''
HEARTBEAT_INTERNAL_PASSWORD=''

# User 'monitoring_internal' (custom)
#
# The user Metricbeat uses to collect monitoring data from stack components.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/how-monitoring-works.html
MONITORING_INTERNAL_PASSWORD=''

# User 'beats_system' (built-in)
#
# The user the Beats use when storing monitoring information in Elasticsearch.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
BEATS_SYSTEM_PASSWORD=''

the last step is to share our logs files with the logstash's container

Open docker-compose.yml file in ~/desktop/dev/docker-elk/ find logstash: service in volumes: add two more directories:
- /ABSOLUTE_PATH_TO_THE_LOG_DIRECTORY/users-ws.log:/var/log/microservices/users-ws.log
- /ABSOLUTE_PATH_TO_THE_LOG_DIRECTORY/albums-ws.log:/var/log/microservices/albums-ws.log

the left side from the colon is your physical path to the file, the right side from the colon is the mounted path to the file within the docker-contaiter.

Now, we're good to go.

Open terminal in ~/desktop/dev/docker-elk/ and run docker-compose up -d the "-d" key for detached mode.

Eventually you will get:

Screenshot 2023-04-11 at 20 18 12

Screenshot 2023-04-11 at 20 16 54

Screenshot 2023-04-11 at 20 16 00

Screenshot 2023-04-11 at 20 20 15

The last command you will need to execute in the future (to dismount entirely the whole thing) is:

open terminal in ~/desktop/dev/docker-elk/ and run docker-compose down -v

It would be really quick provided you don't encounter any errors.

Sleuth and Zipkin dependencies

In order to get all parameters in application.yml you need to engage another one dependency

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
            <version>3.1.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin</artifactId>
            <version>3.1.7</version>
        </dependency>
spring:
  zipkin:
    base-url: http://localhost:9411
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1
```~

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.